What are the differences between ArrayList and Vector?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
ArrayList and Vector are both resizable-array implementations of the List interface, so they look similar at first glance. The practical differences are mostly about synchronization, API age, and what you should choose in modern Java code.
Similarities First
Both classes store elements in an indexed array that grows when needed. Both preserve insertion order, allow duplicates, and provide random access with get(index).
In single-threaded code, both examples behave the same way for basic operations. That is why many beginners wonder whether there is still any meaningful difference.
Synchronization Is the Main Behavioral Difference
Vector synchronizes its individual methods. ArrayList does not. That means Vector adds locking overhead to method calls such as add, get, and remove, while ArrayList is faster in the common case where one thread owns the list or external synchronization is already present.
This modern pattern is usually preferred over reaching for Vector automatically. It makes synchronization explicit and lets you choose the appropriate collection implementation first.
It is also important to remember that Vector being synchronized does not solve every concurrency problem. Compound operations such as "check then act" or iteration plus modification still need additional coordination.
API Age and Design Style
Vector is a legacy class from early Java. It is not deprecated, but it carries older naming conventions and compatibility features such as elements() returning an Enumeration. ArrayList was added later as part of the collections framework and fits modern Java style better.
That code works, but in new programs you would normally write a for loop, an iterator, or a stream pipeline instead.
Capacity Growth and Performance Notes
Both lists grow automatically, but they do not necessarily use the same growth strategy. That matters much less than synchronization overhead and overall access patterns, but it does mean you should not assume identical resizing behavior.
For most real applications, the practical guidance is simple:
- Use
ArrayListfor general-purpose list storage. - Use
Collections.synchronizedList(new ArrayList<>())if you need a synchronized wrapper. - Consider concurrent collections such as
CopyOnWriteArrayListif your access pattern is specifically concurrent and read-heavy.
This advice is stronger than saying "Vector is slower." The better point is that Vector is usually not the collection you would choose first in a new design.
When Vector Still Appears
You may still encounter Vector in older codebases, older libraries, or interview questions. If you are maintaining such code, the class is still valid Java. There is no rule that says it must be removed immediately.
What matters is understanding the tradeoff. If the code does not actually rely on synchronized method calls, replacing Vector with ArrayList may simplify intent and remove unnecessary locking. If the code does rely on synchronization, then migration needs more thought because switching to ArrayList changes thread-safety expectations.
Common Pitfalls
- Assuming
Vectoris automatically the right answer for multithreaded code. - Forgetting that iteration over a synchronized list still needs external synchronization.
- Treating
ArrayListandVectoras identical except for performance. - Using
Vectorin new code when a clearer modern collection choice exists. - Replacing
Vectorin legacy code without checking whether callers relied on synchronized methods.
Summary
- '
ArrayListandVectorare both resizable indexed lists.' - '
Vectorsynchronizes individual methods, whileArrayListdoes not.' - '
ArrayListis the usual default choice in modern Java.' - If synchronization is needed, prefer an explicit wrapper or a concurrent collection chosen for the workload.
- '
Vectorstill works, but it is mainly a legacy API rather than the first recommendation for new code.'

