Can anyone tell me what is the difference between ArrayList and
Vectors?
Michael Rauscher - 17 Apr 2007 07:28 GMT
> Can anyone tell me what is the difference between ArrayList and
> Vectors?
The methods of Vector are synchronized, the methods of ArrayList are not.
Bye
Michael
Ian Wilson - 17 Apr 2007 10:28 GMT
>> Can anyone tell me what is the difference between ArrayList and
>> Vectors?
>
> The methods of Vector are synchronized, the methods of ArrayList are not.
And ArrayList is newer and seems to be preferred for new development.
There are ways of synchronising Arraylists if you need to.
Lew - 17 Apr 2007 12:33 GMT
Shraddha wrote:
>>> Can anyone tell me what is the difference between ArrayList and
>>> Vectors [sic]?
Michael Rauscher wrote:
>> The methods of Vector are synchronized, the methods of ArrayList are not.
> And ArrayList is newer and seems to be preferred for new development.
> There are ways of synchronising Arraylists if you need to.
Also, Vector contains many methods not part of the Collections framework.

Signature
Lew
Andrew Thompson - 17 Apr 2007 10:43 GMT
>Can anyone tell me what is the difference between ArrayList and
>Vectors?
For a detailed discussion of Vector/ArrayList and
LinkedList, see this recent thread..
<http://www.javakb.com/Uwe/Forum.aspx/java-programmer/33059/Vector-vs-LinkedList
HTH

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Patricia Shanahan - 17 Apr 2007 15:04 GMT
> Can anyone tell me what is the difference between ArrayList and
> Vectors?
The java.util collections were redesigned for release 1.2, with a
consistent system of interfaces, Iterator instead of Enumeration, and no
synchronization unless you ask for it through
Collections.synchronizedList etc.
ArrayList is part of the newer design, and has no left overs from
earlier versions.
Vector is older. It was modified to fit into the new design as well as
possible, but had to maintain backwards compatibility. That includes
synchronization, as well as methods that duplicate functionality in
slightly different ways.
If you have a choice, use ArrayList. You need to be aware of Vector in
case you come across it in older code.
Patricia
Chris Smith - 18 Apr 2007 13:35 GMT
> Can anyone tell me what is the difference between ArrayList and
> Vectors?
The reason that ArrayList is a different class from Vector is that
Vector is older. In the 1.2 release cycle, Java added the Collections
API; a set of various container implementations that follow a similar
organization. The older Vector class violated several of the principles
of the new Collections API, and couldn't be fixed to follow them without
breaking compatibility with existing code. Instead, a new class was
introduced.
The biggest difference is that Vector is synchronized automatically, so
that certain trivially simple multithreaded uses can be safely done (but
watch out! Most non-trivial things still require some more coordination
on your part.) An ArrayList, by contrast, would need to be wrapped with
Collections.synchronizedList if you want its methods to be synchronized.
IIRC, a second difference has to do with growth policy, and can affect
the performance of the implementation.

Signature
Chris Smith