Course contentsShow
← Java
Lesson 1030 of 2,87024. List ImplementationsFree lesson

What Is Vector: A Legacy Synchronized List

Understand Vector's role as Java's original thread-safe list and why it's now considered legacy.

What Is Vector: A Legacy Synchronized List

You'll learn what Vector is, why it was Java's original thread-safe list, and why modern code avoids it.

The Original Thread-Safe List

Vector was one of Java's first collection classes, introduced in Java 1.0 (1996) — before the Collections Framework even existed. It behaves almost exactly like ArrayList: it's backed by a dynamic array, grows automatically, and provides indexed access to elements.

The key difference? Every method in Vector is synchronized, making it thread-safe by default. When multiple threads access a Vector simultaneously, built-in locks prevent data corruption.

Why "Legacy"?

While thread-safety sounds great, Vector's approach is now considered outdated:

  1. Blanket synchronization hurts performance: Even when you're using Vector in single-threaded code (the most common case), you pay the cost of acquiring and releasing locks on every operation.

  2. Method-level locking isn't enough: Synchronizing individual methods doesn't make compound operations (like "check-then-add") thread-safe. You'd still need external synchronization for complex logic.

  3. Better alternatives exist: The Collections Framework provides both ArrayList (fast, unsynchronized) and proper concurrent collections like CopyOnWriteArrayList that are designed for modern multi-threaded scenarios.

The Analogy

Think of Vector as a store where every customer must wait in line for a clerk to unlock each individual shelf — even when the store is empty. Modern alternatives let customers browse freely when safe, and use smarter locking strategies when actually needed.

Key Takeaway:
Vector is Java's original synchronized list implementation, but it's now considered legacy — use ArrayList for single-threaded code and modern concurrent collections for multi-threaded scenarios.