In this tutorials, we are going to understand the most important interview question in Java collections : what is the difference between ArrayList vs Vector

This question is commonly asked interview question for freshers to check the roots of the collection framework.

Recommended : What is ArrayList in Java

Recommended : What is Vector in Java

ArrayList vs Vector :

For this tutorials, I have collected the most important differences of ArrayList vs Vector, which will impressed by the interviewer. These are also help full to understand the internals of Java collections.

1) Synchronized or Thread-safe :

ArrayList class is not synchronized, that means it is not thread safe where as Vector is thread safe. We can say like all the methods which are implemented in the Vector are synchronized, so that if we work on multi threaded environment it is highly recommended that to use Vector instead of ArrayList.

2) Increasing capacity :

As we know that Java Collections are grow in size when ever it needs. Here Vector and ArrayList have the same default capacity of 10. But a specific thresh-hold value Vector will be increment the size by double. where as ArrayList increments the size by 50%.

3) Change increment Size :

We can change the Vector’s default increment size by using the size(int size) method available in Vector class, where as there is no way to set the increment size in ArrayList it will increment by 50% directly we can’t change it any more.

4) Performance ArrayList vs Vector :

We can not say directly which is good performance over ArrayList and Vector, based on the requirement we should go with ArrayList or Vector. But as part of the synchronized behaviour of Vector class is bit low performance since it will not allow the multi accessing.

5) Data Traverse :

To traverse the elements ArrayList uses Iterator interface, where as Vector uses both Enumeration and Iterator interfaces.

6) Versions :

Vector is a legacy class which was included in Java in the 1.x versions, where as ArrayList was included in Java 2.x version as part of the Collection Framework.

References :

Happy Learning 🙂