|
Answer» Following are the differences between ArrayList and Vector in java : - Vector is synchronized, which means that only one thread can access the code at a time, however, ArrayList is not synchronized, which means that multiple threads can operate on ArrayList at the same time. In a multithreading system, for example, if one thread is executing an add operation, another thread can be performing a removal action.
If multiple threads access ArrayList at the same time, we must either synchronize the code that UPDATES the list fundamentally or enable simple ELEMENT alterations. The addition or deletion of element(s) from the list is referred to as structural change. It is not a structural change to change the value of an existing element.
- Data Growth: Both ArrayList and Vector dynamically expand and SHRINK to make the most use of storage space, but the manner they do it is different. If the number of elements in an array exceeds its limit, ArrayList increments 50% of the current array size, while vector increments 100%, thereby doubling the current array size.
- Performance: ArrayList is faster than vector operations because it is non-synchronized, but vector operations are slower since they are synchronized (thread-safe). When one thread WORKS on a vector, it acquires a lock on it, requiring any other threads WORKING on it to wait until the lock is released.
- Vector can traverse over its elements using both Enumeration and Iterator, whereas ArrayList can only traverse using Iterator.
|