File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Vector vs ArrayList" Watch "Vector vs ArrayList" New topic

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

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.<br />I can because I think I can...
I agree. Here's the link:
subject: Vector vs ArrayList
jQuery in Action, 3rd edition