ArrayList and Vector both use Array as a data structure internally. However there are few differences in the way they store and process the data. Below is the list of difference:
Point of Distinction | ArrayList | Vector |
---|---|---|
Synchronization | Non-Synchronized, which means multiple threads can work on ArrayList at the same time. | Synchronized. This means if one thread is working on Vector, no other thread can get a hold of it. |
Resize | Grow by half of its size when resized. | Double the size of itself by default when grows. |
Performance | Fast. Better performance as its non-synchronized. | Slow. Poor performance as they are thread-safe. |
Fail-Fast | Iterator and Listiterator returned by ArrayList are fail-fast. | Enumeration returned by Vector is not fail-fast. |
Syntax | ArrayList<T> al = new ArrayList<T>(); | Vector<T> v = new Vector<T>(); |
Thread Safe | No | Yes |
Legacy Class | No | Yes |
Define Increment Size | No | Yes |
Traversing | Iterator for Traversing. | Use Iterator and Enumeration both. |
Size to Array | If an element is inserted into the Array List, it increases its Array size by 50%. | Vector defaults to doubling size of its array. |
Comments