Wednesday 7 December 2016

Difference : ArrayList Vs Vector


Given below are the parameters on which ArrayList and Vector differs from each other :

1.      Synchronization :
ArrayList is non-synchronized. It is for same reason that multiple threads can operate on ArrayList at the same time.

Vector is synchronized. It is for same reason that two threads cannot get hold of a vector at the same time. If one thread is executing an operation on vector, other thread needs to wait till the executing thread releases it.

2.      Performance :
ArrayList is better performance-wise. As you know by now, ArrayList is non-synchronized so multiple threads can work on ArrayList at the same time.

Vector lags performance wise when compared to ArrayList. Vector is thread-safe. When a thread is performing any operation on Vector then it gets a lock. If other thread wants to perform operation on same Vector then it needs to wait until the Vector is unlocked (released) by thread in action.

3.      Size :
ArrayList grows by half of its size, if required.
Vector grows by double of its size, if required.

5 comments:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.