← Back to Java

ArrayList vs Vector

JavaEntryjava

The Question

What are the differences between ArrayList and Vector?

What a Strong Answer Covers

  • Vector = legacy synchronized thread-safe
  • ArrayList = not synchronized faster
  • Vector grows 100% vs ArrayList 50%
  • ArrayList uses Iterator
  • Vector supports Iterator + Enumeration

Senior-Level Answer

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`.

Key Differences

AspectArrayListVector
Thread safetyNoYes — all methods synchronized
PerformanceFaster (no lock overhead)Slower
Growth factor50% (×1.5)100% (×2) by default
Introduced inJava 1.2 (Collections Framework)Java 1.0 (legacy)
Legacy methodsNoYes — elements(), addElement(), etc.
Modern recommendationYes — default List implementationNo — use concurrent alternatives

What Separates a 2/3 from a 3/3

2/3 — Passing but Incomplete

Identifies synchronization as the key difference and explains that ArrayList is the modern default.

3/3 — Strong Answer

Also covers the growth factor difference, legacy API on Vector, the java.util.concurrent alternatives, and the compound-operation thread-safety caveat.

Common Mistakes

  • Recommending Vector for thread safety in new code instead of ConcurrentLinkedDeque or CopyOnWriteArrayList.
  • Assuming Vector's method-level synchronization makes compound operations atomic — it does not.
  • Not knowing that ArrayList grows by 50% while Vector doubles — a detail examiners often probe.

Follow-Up Questions

  • If Vector is thread-safe, why is `if (!v.isEmpty()) v.remove(0)` still not safe for concurrent use? — Each method call is atomic, but the check and the remove are two separate lock acquisitions — another thread can modify the list between them.
  • What java.util.concurrent class would you use instead of Vector in a modern concurrent application? — CopyOnWriteArrayList for read-heavy; Collections.synchronizedList for balanced; ConcurrentLinkedQueue for queue semantics.
  • How does ArrayList's growth strategy affect performance when building large lists? — Frequent reallocations can be avoided by pre-sizing with new ArrayList<>(expectedCapacity), eliminating copies.

Related Questions

  • JVM vs JRE vs JDK
  • Java Platform Independence
  • How JVM Works
  • Main Features of Java
  • public static void main

Can You Explain This Cold?

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
GrindQuestionsAITechnical interview assessment
TermsPrivacyAbout