This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Vector vs ArrayList
 
Similar Threads
Multiple Thread allow to change single variable
array
performance : arraylist vs vector
type casting
Array List vs Vector