Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Please tell me difference...

Thread view: 
Shraddha - 17 Apr 2007 05:22 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.