Legacy Collections in Java
Legacy Collections are the oldest data structure classes in Java, created before Java 1.2—before the modern Collection Framework was introduced.
Even though Java later added the Collection Framework, these classes were kept for backward compatibility, and most of them were redesigned internally to work with the new framework.
All legacy classes are available in the java.util package.
What Are Legacy Collections?
Legacy Collections refer to these old classes and interfaces:

- Vector
- Stack
- Hashtable
- Properties
- Enumeration (legacy iterator)
These classes:
- Are synchronized (thread-safe by default)
- Belong to JDK 1.0
- Have older method names like
addElement() - Use Enumeration instead of Iterator
- Are slower than modern alternatives
- Still supported—but not recommended for new projects
1. Vector (Legacy List Implementation)
What is Vector?
Vector is a dynamic array similar to ArrayList, but it is synchronized, making it thread-safe but slower.
Iterable
└── Collection
└── List
└── VectorKey Points
- Maintains insertion order
- Allows duplicates
- Thread-safe → slower than ArrayList
- Part of List hierarchy
Example
import java.util.*;
Vector<String> vec = new Vector<>();
vec.add("Java");
vec.add("Python");
vec.add("C++");
System.out.println(vec);
2. Stack (Legacy LIFO Implementation)
What is Stack?
Stack is a legacy LIFO (Last-In-First-Out) data structure that extends Vector.
Key Points
- Built on top of Vector
- Fully synchronized
- Works on push/pop operations
Example
import java.util.*;
Stack<Integer> stack = new Stack<>();
stack.push(10);
stack.push(20);
stack.push(30);
System.out.println(stack.pop()); // 30
Modern Replacement:
Use ArrayDeque instead (much faster and recommended).
3. Hashtable (Legacy Map Implementation)
What is Hashtable?
Hashtable is a synchronized Map implementation that stores data in key-value pairs.
Map
└── HashtableKey Points
- Thread-safe
- Does not allow null key or null values
- Slower than HashMap
- Legacy alternative to HashMap
Example
import java.util.*;
Hashtable<Integer, String> table = new Hashtable<>();
table.put(1, "Java");
table.put(2, "Python");
System.out.println(table.get(1));
Modern Replacement:
Use HashMap or ConcurrentHashMap (better performance).
4. Enumeration (Legacy Iterator)
What is Enumeration?
Enumeration is an old interface used to iterate over legacy classes like Vector and Hashtable.
Key Points
- Forward-only traversal
- Cannot remove elements
- Used only in legacy classes
- Replaced by Iterator & ListIterator
Example
import java.util.*;
Vector<String> vec = new Vector<>();
vec.add("Java");
vec.add("C++");
Enumeration<String> en = vec.elements();
while (en.hasMoreElements()) {
System.out.println(en.nextElement());
}
5. Properties (Configuration Storage Class)
What is Properties?
Properties is a specialized class (extends Hashtable) used to store String–String key-value pairs, mostly for configuration files.
Key Points
- Keys & values stored as Strings only
- Used for
.propertiesconfig files - Common in Spring, JDBC, and Java applications
Example
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
Properties p = new Properties();
p.setProperty("username", "admin");
p.setProperty("password", "12345");
p.store(new FileOutputStream("config.properties"), "Config File");
}
}
Why Are They Called "Legacy"?
Because they:
- Were created before the modern Collection Framework
- Use old method names (
addElement(),removeElement()) - Use Enumeration instead of Iterator
- Are synchronized by default → slower
- Have outdated design
- Replaced by newer classes like ArrayList, HashMap, ArrayDeque
When Should You Use Legacy Collections?
Use them only when:
- Working on older (legacy) codebases
- You specifically need built-in synchronized operations
Otherwise → avoid them.
Points to Remember
| Legacy Class | Description | Modern Replacement |
|---|---|---|
| Vector | Synchronized dynamic array | ArrayList |
| Stack | LIFO (extends Vector) | ArrayDeque |
| Hashtable | Synchronized Map, no nulls | HashMap / ConcurrentHashMap |
| Enumeration | Legacy iterator | Iterator / ListIterator |
| Properties | Config storage (String–String) | Still used (no replacement) |
