I am adding elements in a vector. When I am getting the elements out of the vector they are not in the same order as I entered them. I want to use Vector as I need them synchronized. How can I get the elements in the same order. Thanks, Anj
Keith Lynn has told you that items added to a Vector are added to the end. So they are retained in the order of addition. To get them in order, use the standard methods
Iterator,
for-each loop
for loop.
If this is for an assignment, use an Iterator.
As Keith Lynn has suggested, if you don't need synchronization, you might be better using an ArrayList.
I don't understand how are you getting the elements in a different order,as compared to the order in which you have inserted them. I have never got the sequence of elements in the different order.Can you give some example.