In Java, when you iterator over a Vector<String[]>, why is .next() an Object that needs to be casted to String[], to use each element as a String[]?
EDIT:
Here is my code:
Iterator itr = getIdAndName().iterator();
while( itr.hasNext() ) {
String[] stringArray = (String[])itr.next();
String id = stringArray[0];
String name = stringArray[1];
System.out.println(id + ": " + name);
}
getIdAndName() returns Vector<String[]>.
It isn’t. The only thing I can think of is you’re not typing your iterator, i.e. you’re doing this:
when you should be doing:
Well, in most cases you don’t actually need the iterator directly, so you could just use: