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 / March 2007

Tip: Looking for answers? Try searching our database.

ArrayList vs. Vector

Thread view: 
John T - 19 Mar 2007 02:26 GMT
It seems to me that these are somewhat interchangeable.  I would assume,
based on my past posts, that I am wrong, but if someone could point me
to a place where I could get the right answer I would appreciate it...

btw - I have downloaded that mindprod site to one of my network drives
and consult it regularly.
Arne Vajhøj - 19 Mar 2007 02:32 GMT
> It seems to me that these are somewhat interchangeable.  I would assume,
> based on my past posts, that I am wrong, but if someone could point me
> to a place where I could get the right answer I would appreciate it...

They are almost equivalent in functionality.

I would recommend ArrayList.

The synchronized capability of Vector is usually of no real benefit.

Arne
Jeff Higgins - 19 Mar 2007 03:20 GMT
> It seems to me that these are somewhat interchangeable.  I would assume,
> based on my past posts, that I am wrong, but if someone could point me to
> a place where I could get the right answer I would appreciate it...
>
> btw - I have downloaded that mindprod site to one of my network drives and
> consult it regularly.

http://forum.java.sun.com/thread.jspa?threadID=632507&messageID=3658931

http://www.javaworld.com/javaworld/javaqa/2001-06/03-qa-0622-vector.html
Patricia Shanahan - 19 Mar 2007 03:31 GMT
> It seems to me that these are somewhat interchangeable.  I would assume,
> based on my past posts, that I am wrong, but if someone could point me
> to a place where I could get the right answer I would appreciate it...

The single most important place to look for information about API
classes is the API documentation.

There are two major differences described in the documentation:

1. Vector methods are synchronized. ArrayList methods are not, but you
can build a Synchronized list from it using
Collections.synchronizedList(new ArrayList(...))

2. Vector existed before the List interface, but was retrofitted to
implement it.

You can check those statements in the API documentation. The rest of
this article is my opinions on the implications:

Because of point #2, Vector contains methods that are not in the List
interface, such as the elements method that returns in Enumeration. The
Enumeration documentation recommends using Iterator instead.

There are uses for both synchronized and unsynchronized List. If you use
ArrayList, you can base both on a single class. If you use Vector, you
should still learn ArrayList for cases where you don't need synchronization.

Overall, I think there is a good case for abandoning Vector except for
backwards compatibility, and using ArrayList in all new code.

Patricia


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.