*
The moose likes Java in General and the fly likes Vector vs ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Vector vs ArrayList" Watch "Vector vs ArrayList" New topic
Author

Vector vs ArrayList

Ravi Kotha
Ranch Hand

Joined: Mar 02, 2006
Posts: 53
What is the scope of Vector and ArrayList in Java? When we should use which one? Can somebody explain me?
Lucas Lee
Ranch Hand

Joined: Oct 02, 2006
Posts: 53
You should check the JDK API document for these two classes first.
The major difference is Vector is not synchronized while ArrayList is synchronized. That is, for more often situation, you should use ArrayList for better performance.
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
It's vice versa. Vector has synchronized methods.
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
Hi,

Methods in Vector are synchronised which means they are thread-safe and thus preclude access to the Vector elements by concurrent threads.But this imposes additional overhead on the JVM as it has to acquire and release locks on the vector objects under consideration.

This is not possible in ArrayList since those methods are not synchronised and hence are faster in performance.

Use Vector only if it will be accessed by multiple threads at a time else ArrayList is always better.

milan


Milan.<br />I can because I think I can...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector vs ArrayList