Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector vs ArrayList

 
Ravi Kotha
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the scope of Vector and ArrayList in Java? When we should use which one? Can somebody explain me?
 
Lucas Lee
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's vice versa. Vector has synchronized methods.
 
Milan Jagatiya
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic