I'm obtaining a Vector from a product's API.
Vector<?> dataVector = dataAPI.getReturnVector();
The vector is expected to contain Strings as value. I'm able to print the size of the vector as 2. But for some reason I'm not able to iterate and print the values.
I tried
Iterator<?> iter = dataVector.iterator();
while( iter.hasNext()) {
System.out.println(iter.next());
}
I always end up getting a
[java.lang.String; cannot be cast to java.lang.String
I used
iter.next().getClass().getName()
and it turned out to be java.lang.String
only.
I googled a bit and found a similar problem at http://prideafrica.blogspot.com/2007/01/javalangclasscastexception.html
I tried to set the generics as String[]
, but ended up with the same error.
If the vector contains java.lang.String
, why do I get this cast exception? How can I print the actual values?
Kindly provide your suggestions.
[java.lang.String;
? That would be the internal name of a String array. – Shepard