Welcome to our interview preparation section on Projectsgeek where we will try to provide updated and deep knowledge on java language interview questions. So today we will talk about major difference between Array List And Vector in core java collection framework.
Difference Between Array List And Vector
|This is legacy object which is present from the beginning version of java.||This is introduced in Java version 1.2 with other collection classes.|
|This is synchronized class which means its is thread safe.
Explanation: Vector is thread safe and will be accessed by only one thread at a time. So this is good choice for multi threading applications.
|This is not synchronized and not thread safe.
Explanation: Array List is not thread safe that means it can be access my multiple threads at same time unlike vector.
|This is slower than array List because of synchronized class.
Explanation: As this is thread safe each thread needs to wait for the availability to process the data using this data structure. So this will increase the wait time and slow the application.
|This is faster than the vector as this is not thread safe. This will allow multi threading access to applications.|
|Capacity Increment: Vector doubles the size of array each time it reaches the maximum size.||Capacity Increment: Array list increment the array size by 50% each time it reaches the maximum size limit. Internally it creates new array with incremented size and copy all the data from old array. Now this old array will be recycled as per JVM Policy.|
|We can use enumerator as well as iterator with vector.||We can use only iterator with ArrayList.|
- We can use Vector when you are working in multi threaded environment as its thread safe.
- Applications which don’t have performance concerns they can use vector. It is slow.
- If your Application needs to be faster and you don’t want performance issues you can go for Array List. It is faster collection.
- If you do not have thread safe concerns you can use ArrayList.