Confusion with Vector
Hi,
Vector is a List. And List is an ordered collection (also known as a sequence) as documented in javadoc for List.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html
I used a vector and added the following values
"Orange"
"Mango"
"Apple"
and then printed all the element of this vector using a for loop.
I was assuming that as it is a list implementation, i wll get the sorted result
as Apple, Mango and then Orange.
But I got the items in the sequence as I had inserted into.
Am I meaning something wrong whatever I found in documentation for Vector?
Thanks
[653 byte] By [
JL.Nayaka] at [2007-11-27 11:24:48]

> I was assuming that as it is a list implementation, i wll get the sorted result
"Ordered" does not mean "sorted".
> But I got the items in the sequence as I had inserted into.
That's the expected behavior. If you want the elements sorted, use a different implementation of List or use Collections.sort().
~
> > Check TreeSet
>
> If you do, make sure you want a Set and not a List.
> :o)
>
> ~
Plus even when dealing with lists, its better to work with ArrayList than Vectors, if synchronization is an issue there are concurrency classes as well
> yes exactly . Vector is ordered according to
> insertion order.meaning elements will be fetched in
> the exact same order u inserted them.
>
> Unlike ArrayList which is ordered according to
> indexes.
I thought you were killing yourself. ArrayList orders elements the same way Vector does, by the way
> yes exactly . Vector is ordered according to
> insertion order.meaning elements will be fetched in
> the exact same order u inserted them.
>
> Unlike ArrayList which is ordered according to
> indexes.
Wrong, exactly. Both Vector and ArrayList use insertion order. sjosh_theone, I recommend you concentrate on getting your file names straight* before giving out any more "advice".
*
http://forum.java.sun.com/thread.jspa?threadID=5197936
~