[Biojava-l] Navigating a Vector

Rahul Karnik rahul at genebrew.com
Mon Nov 1 21:54:50 EST 2004


mark.schreiber at group.novartis.com wrote:
> I'm not sure you can, especially because iterators on Vectors are not 
> gaurenteed to operate in any special order. If possible you should use an 
> ArrayList or LinkedList. In this case you will be able to find the index 
> or even ask for items by their index.

While order is not guuranteed, you can actually loop over a Vector using 
a for loop and the Vector elementAt(int index) method. Besides, if you 
create a [Array|Linked]List from the Vector, you would get the same 
order. If you want to use an Iterator, Vector implements the iterator() 
method as well.

The only difference between Vector and ArrayList is that Vector is 
synchronized (threadsafe) and ArrayList is not.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html

Thanks,
Rahul


More information about the Biojava-l mailing list