Help with Casting Vectors and String.valueOf()
I'm new to this forum but if you guys could help me out real quick, I would appreciate it.
So I made this vector which is full of integers that I parsed previously from Strings. So the code looked something like:
size is an integer, sizeString is a String, showSize is a vector.
size = Integer.parseInt(sizeString);
This part works flawlessly but when I add this part of the code:
I get an error saying "inconvertible types found: java.lang.Object required: int"
showString = String.valueOf(((int)showSize.get(0)));
I thoguht that the casting of the int of showSize will make the parameters an int but I guess not. Any suggestions on how to fix this? Thank you in advance!
Re: Help with Casting Vectors and String.valueOf()
Autoboxing is taking place, converting your int to an Integer.
Use: Vector<Integer> vector = new Vector<Integer>(); where the Integer is specified rather than assumed
or: Vector<Integer> vector = new Vector<>();
but not: Vector vector = new Vector();
When you get your value back out it is in Integer form, and should auto-unbox itself if you just remove the cast.