1.

ArrayList vs Vector in Java

Answer»

The java.util.ArrayList class extends the AbstractList class. It is a part of the collection framework. The ArrayList is initialized a size which is capable of INCREASING or decreasing its size when OBJECTS are separated from the collection.

The java.util.Vector class represents DYNAMIC data structures which can expand when a new element is added to them. Vectors are synchronized and contain MANY methods that are not a part of the Collections framework in Java.

Here are a few key differences between Vectors and ArrayList:

Basis
Vector
ArrayList
Threads
Vector thread is thread safe as only one thread is allowed to work at a time
ArrayList is not thread safe as multiple threads are allowed to work at a time
Synchronization
Every method available in Vector is Synchronized
Every method available in ArrayList is not Synchronized
Performance
Threads are required to hold-up on Vector object and hence their performance is low as compared to ArrayList.
Threads are not required to hold-up on ArrayList object and hence their performance is high as compared to Vector
Growth
Doubles its size when it grows
Grows by half of its size
Application
Multi user application
Single user application
Legacy class
Vector is a legacy class, INTRODUCED in JDK 1.0
ArrayList is a non legacy class, introduced in JDK 1.2
Traversal
Uses enumeration for traversal.
Uses Iterator/ListIterator for traversal.


Discussion

No Comment Found