What are the differences between ArrayList and Vector?
Both `ArrayList` and `Vector` are `List` implementations backed by a resizable array, and they share the same core operations. The primary difference is synchronization.
`Vector` was introduced in Java 1.0 and predates the Collections Framework. Every public method — `add()`, `get()`, `remove()`, `size()` — is `synchronized`. This makes `Vector` thread-safe for individual method calls but at the cost of lock acquisition on every operation, even in single-threaded code.
`ArrayList` was introduced in Java 1.2 as part of the Collections Framework. Its methods are not synchronized, making it significantly faster in single-threaded contexts. For concurrent access, you explicitly choose an appropriate strategy: `Collections.synchronizedList(new ArrayList<>())` for simple wrapping, or `CopyOnWriteArrayList` from `java.util.concurrent` for read-heavy workloads.
A secondary difference is growth strategy. When capacity is exceeded, `ArrayList` grows by 50% (current capacity × 1.5). `Vector` doubles its size by default, though this is configurable via a capacity increment parameter in its constructors.
`Vector` also has legacy methods like `elements()` (returns an `Enumeration`) that predate the `Iterator` interface. These are now redundant.
In practice, `Vector` is considered a legacy class. The Java documentation and Effective Java both recommend `ArrayList` for single-threaded use and `java.util.concurrent` classes for multithreaded use. `Vector` is rarely the right answer in modern code.
One nuance worth noting: even though `Vector` is synchronized, compound operations (check-then-act) still require external synchronization. `if (!v.isEmpty()) v.remove(0)` is not atomic even with `Vector`.
| Aspect | ArrayList | Vector |
|---|---|---|
| Thread safety | No | Yes — all methods synchronized |
| Performance | Faster (no lock overhead) | Slower |
| Growth factor | 50% (×1.5) | 100% (×2) by default |
| Introduced in | Java 1.2 (Collections Framework) | Java 1.0 (legacy) |
| Legacy methods | No | Yes — elements(), addElement(), etc. |
| Modern recommendation | Yes — default List implementation | No — use concurrent alternatives |
Identifies synchronization as the key difference and explains that ArrayList is the modern default.
Also covers the growth factor difference, legacy API on Vector, the java.util.concurrent alternatives, and the compound-operation thread-safety caveat.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment