Originally posted by pascal betz:
first: you might want to look at the java.util.List and (one of the implementations java.util.ArrayList); unless required you should use these classes instead of Vector (Vector is synchronized, ArrayList is not. Butboth iomplement the List itnerface).
But your problem still stays :-)
Iterating over a List is possible in two ways:
- use the index
- use the iterator
if you check out the API doc of List you will find the methods to get elements out of a List using the index of the item.
also in the API you will find the Iterator interface which can also be used to iterate over a List.
btw: in your example code there is just one element in your Vector: a String (and i assume you want to have two items beeing the two names)
lets see if this gets you further....
I tried using the ArrayList, it worked fine, but I am not sure why I put the line Object names = (Object) iter.next(); in the for loop.
I am not sure why I put the line Object names = (Object) iter.next(); in the for loop.
And I also did the vector one, it also works but throws an exception after printing the contents. please help.