Quick revision
The short answer
Vector, Hashtable, Stack and Enumeration date from Java 1.0 and were fitted into the Collections Framework in Java 1.2; their public methods are synchronized, which costs little when uncontended but does not make check-then-act sequences thread-safe. In new code we use ArrayList instead of Vector, HashMap or ConcurrentHashMap instead of Hashtable, which also forbids null keys and values, ArrayDeque with push and pop instead of Stack, and Iterator, which supports remove, instead of Enumeration.
What to remember
In this answer, we saw that Vector, Hashtable, Stack and Enumeration come from Java 1.0 and were retrofitted into the Collections Framework in 1.2. Their synchronized methods make each call safe but not sequences of calls, so they offer little real thread safety. In new code we use ArrayList, HashMap or ConcurrentHashMap, ArrayDeque and Iterator, keeping in mind the differences in null handling and growth when we migrate.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Vector, Hashtable, Stack and Enumeration date from Java 1.0 and were fitted into the Collections Framework in Java 1.2; their public methods are synchronized, which costs little when uncontended but does not make check-then-act sequences thread-safe. In new code we use ArrayList instead of Vector, HashMap or ConcurrentHashMap instead of Hashtable, which also forbids null keys and values, ArrayDeque with push and pop instead of Stack, and Iterator, which supports remove, instead of Enumeration.
Why this question is asked
We still meet these classes in old code, in a few JDK APIs and in interview questions, and they look perfectly usable: Vector is a list, Hashtable is a map. Interviewers ask about them because the answer shows whether we understand why the modern classes replaced them, which is mostly about thread safety and design, not speed. In this answer, we will recap where the legacy classes came from, look at what synchronizing every method really gives us, and then go through each class and its modern replacement with code.
1A Quick Recap: Where They Came From
Java 1.0, in 1996, shipped with only a few container classes: Vector, a growable array; Hashtable, a hash map; Stack, a last-in, first-out stack built on Vector; and Enumeration, an interface for stepping through elements. In 1998, Java 1.2 introduced the Collections Framework with List, Set, Map and their implementations. Rather than remove the old classes, which would have broken existing programs, the designers retrofitted them: Vector was made to implement List, and Hashtable to implement Map.
The old classes kept their original method names alongside the new ones, so Vector has both addElement and add, and Hashtable has both elements() and values(). They also kept their main design choice: nearly every public method is synchronized.
2What Synchronizing Every Method Gives, and What It Does Not
A synchronized method takes the object's lock for the duration of the call, so two threads cannot run add on the same Vector at once. Each single call is therefore safe. On modern JVMs, taking a lock that no other thread holds is cheap, so in single-threaded code the overhead is small, though not zero.
The problem is that most real operations are sequences of calls, and the lock is released between them. A check-then-act, such as adding a key only if it is absent, can be interleaved by another thread between the check and the act.
Every method on the Hashtable was synchronized, yet the result is wrong, because the lock protected each call, not the whole sequence. ConcurrentHashMap solves this properly by offering atomic compound operations such as merge, compute and putIfAbsent. This is why per-method synchronization gives a false sense of safety: it looks thread-safe but does not protect the operations we actually care about. Iteration has the same issue, since a loop is many calls.
3Vector -> ArrayList
Vector and ArrayList are both arrays that grow when full. The differences are the synchronization and the growth rate. ArrayList grows by half its capacity each time, while Vector, by default, doubles its capacity, or grows by a fixed capacityIncrement if one is set in the constructor. Doubling means fewer resizes but more wasted space.
For single-threaded use, which is most code, ArrayList is the replacement. When threads share a list, Collections.synchronizedList gives the same per-call locking as Vector, with the same limits, and CopyOnWriteArrayList suits read-heavy lists such as listener registries, since iteration needs no lock at all. Often the better answer is a different structure, such as a concurrent queue.
4Hashtable -> HashMap or ConcurrentHashMap
HashMap is the single-threaded replacement. ConcurrentHashMap is the concurrent one, and it is better than Hashtable in two ways: it does not take one lock for the whole map, so reads proceed without locking and writes to different parts of the map rarely contend, and it offers atomic compound operations.
One behaviour difference matters when migrating. Hashtable rejects null keys and null values with NullPointerException. HashMap allows one null key and null values, and ConcurrentHashMap, like Hashtable, rejects both. So replacing Hashtable with HashMap can let nulls in that used to fail fast, and replacing a HashMap with ConcurrentHashMap can start throwing where nulls were stored.
| Legacy | Replacement | Key difference |
|---|---|---|
| Vector | ArrayList (or CopyOnWriteArrayList) | Not synchronized; grows by 50% instead of doubling |
| Hashtable | HashMap, or ConcurrentHashMap | HashMap allows nulls; CHM has atomic compound ops |
| Stack | ArrayDeque (push, pop, peek) | No list methods exposed; not synchronized |
| Enumeration | Iterator | Shorter names and remove() |
5Stack -> ArrayDeque, and Enumeration -> Iterator
Stack extends Vector, which was a design mistake: a stack should only allow push, pop and peek, but because it is a Vector, callers can also insert or remove at any index, breaking the stack discipline. ArrayDeque, used through the Deque interface, provides push, pop and peek at the head, is not synchronized, and is generally faster. It does not allow null elements.
Enumeration was replaced by Iterator, which has shorter method names and adds remove(), the only safe way to remove elements while iterating. When an old API still hands us an Enumeration, Collections.list(en) turns it into an ArrayList, and since Java 9 en.asIterator() adapts it to an Iterator.
6Follow-up questions
Why is a Hashtable iteration not safe while another thread updates it?
Each method locks the table only during that call, and an iteration is many calls, so another thread can change the table between them. The iterators of keySet(), values() and entrySet() are fail-fast and throw ConcurrentModificationException when they detect the change. The old Enumerations from keys() and elements() are not fail-fast, so they may silently skip or repeat entries. To iterate safely, hold synchronized (table) for the whole loop, or use ConcurrentHashMap, whose iterators are weakly consistent and never throw.
Is Vector slower than ArrayList?
Slightly, in single-threaded code, because of the lock on every call, though modern JVMs make uncontended locks cheap. The main reason to avoid it is not speed but that its synchronization does not give real thread safety and signals the wrong intent to readers.
Are these classes deprecated?
No, they are not formally deprecated, because some JDK APIs still use them, such as Properties, which extends Hashtable. They are simply considered obsolete for new code.
7Conclusion
In this answer, we saw that Vector, Hashtable, Stack and Enumeration come from Java 1.0 and were retrofitted into the Collections Framework in 1.2. Their synchronized methods make each call safe but not sequences of calls, so they offer little real thread safety. In new code we use ArrayList, HashMap or ConcurrentHashMap, ArrayDeque and Iterator, keeping in mind the differences in null handling and growth when we migrate.
Open with
These four are Java 1.0 classes, from before the Collections Framework. In Java 1.2 they were retrofitted, so Vector implements List and Hashtable implements Map, but they kept their old method names and their main design choice: almost every public method is synchronized.
Then, if they want more
That makes each single call safe, and the uncontended lock is cheap today, but it does not make sequences safe. A check-then-put on a Hashtable can still lose updates, and iterating while another thread writes can fail. So in new code: instead of Vector, ArrayList; and if threads share it, Collections.synchronizedList or CopyOnWriteArrayList for read-heavy lists.
Vector also doubles when it grows, while ArrayList grows by half. Instead of Hashtable, HashMap for single-threaded use, or ConcurrentHashMap for concurrent use, which has finer-grained locking and atomic operations like merge and computeIfAbsent. One difference to watch: Hashtable rejects null keys and values, HashMap allows them, and ConcurrentHashMap rejects them.
Stack extends Vector, so it exposes list methods like add at an index, which breaks the stack idea; I use ArrayDeque through the Deque interface with push, pop and peek. And Enumeration is replaced by Iterator, which has remove for safe removal during iteration. If an old API gives me an Enumeration, I can use asIterator or Collections.list.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Collections Framework, overview, java.util, package documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Vector, Hashtable, Stack and Enumeration are legacy collections. Explain how they differ...": https://scrivio-interview-library.netlify.app/java/collections-overview/0d9723f270/