Yet another Wrapper Class confused guy.
Java is a pretty much new language to me and I'm still in the early learning process of it, I had myself making some pratice with Vector objects and of curse Wrapper Classes so I could use native variables with it but it looks like that those guides I'm reading from didn't clear my mind about it so much.
So I filled this Vector (data) with a few int numbers inside a setMethod and trying now to pull them out in a getMethod to operate with them; I basically tried to use a for iteration to pick each element and assign it to a Integer variable, and then to revert the number to it's native int type using the intValue() method. The original thing was pretty much like this:
Code:
int pre=0;
for (int i=0; i<data.size();i++){
Integer num = new Integer ( data.get(i) );
per+=num.intValue();
}
which obviously didn't work.
Googling around I somehow managed to accomplish it but I'm not sure if I found the best way to do it so I'd like to be sure about it before moving on:
Code:
int pre=0;
for (int i=0; i<data.size();i++){
String [COLOR="Sienna"]buf[/COLOR] = String.valueOf(data.get(i));
Integer num = new Integer([COLOR="Sienna"]buf[/COLOR]);
per+=num.intValue();
}
So I pull my data out in a string using it's .valueOf before I could convert and treat it as an int. Now the n00b question is, was there a most direct way to accomplish it?