Search

Wednesday, April 13, 2011

What is the Differenece between arrayList and Vector

Difference between Java Vector and Java ArrayList

ArrayList and Vector are very similar to each other. Difference between ArrayList and Vector is as given below

1) ArrayList is not synchronized, while Vector is synchronized.
Vector is synchronized, so its thread safe, ArrayList is not thread safe.  Synchronization causes the performance penalty. So if thread safe collection is not needed then ArrayList should be used instead of the Vector.

2) ArrayList and Vector both are resizable array, and internally uses the array to hold elements of the list.  Capacity of the ArrayList or Vector grows automatically as we add elements to it. By default Vector doubles the capacity when needed, while ArrayList increases the capacity by half.

No comments:

Post a Comment