top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between Vector and ArrayList in Java?

0 votes
435 views
What is difference between Vector and ArrayList in Java?
posted Mar 11, 2016 by Vijay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Differences are:
1.Vector is synchronized while ArrayList is not synchronized -Synchronization and thread safe means at a time only one thread can access the code .In Vector class all the methods are synchronized .That is why the Vector object is already synchronized when it is created and ArrayList is not.
2. Performance-if we talk about performance then vector is slow as it is thread safe . In comparison ArrayList is fast as it is non synchronized .So in ArrayList two or more threads can access the code at the same time, while Vector is limited to one thread at a time.
3. Automatic Increase in Capacity-A Vector defaults to doubling size of its array while when you insert an element into the ArrayList , it increases its Array size by 50% .By default ArrayList size is 10 . It checks whether it reaches the last element then it will create the new array ,copy the new data of last array to new array ,then old array is garbage collected by the jvm .
4. Set Increment Size-ArrayList does not define the increment size . Vector defines the increment size and there is no setSize() method or any other method in ArrayList which can manually set the increment size.
5. Enumerator-Other than Hashtable ,Vector is the only other class which uses both Enumeration and Iterator .While ArrayList can only use Iterator for traversing an ArrayList .

answer Mar 13, 2016 by Shivam Kumar Pandey
...