I get a vector from the product API.
Vector<?> dataVector = dataAPI.getReturnVector();
The vector is expected to contain strings as a value. I can print the vector size as 2. But for some reason I cannot repeat and print the values.
I tried
Iterator<?> iter = dataVector.iterator(); while( iter.hasNext()) { System.out.println(iter.next()); }
I always get
[java.lang.String; cannot be cast to java.lang.String
I used
iter.next().getClass().getName()
and it turned out to be only java.lang.String
.
I searched Google a bit and found a similar problem at http://prideafrica.blogspot.com/2007/01/javalangclasscastexception.html
I tried to set generics as String[]
, but ended up with the same error.
If the vector contains java.lang.String
, why am I getting this exception? How to print the actual values?
Please provide your suggestions.
source share