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:
-
Blanket synchronization hurts performance: Even when you're using
Vectorin single-threaded code (the most common case), you pay the cost of acquiring and releasing locks on every operation. -
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.
-
Better alternatives exist: The Collections Framework provides both
ArrayList(fast, unsynchronized) and proper concurrent collections likeCopyOnWriteArrayListthat 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.