Collections Beginner

Use the Deque interface with ArrayDeque instead of the legacy Stack class.

✕ Legacy Stack
Stack<String> stack = new Stack<>();
stack.push("task");
String next = stack.pop();
✓ Deque API
Deque<String> stack = new ArrayDeque<>();
stack.push("task");
String next = stack.pop();
See a problem with this code? Let us know.
🎯

Better abstraction

Deque explicitly models both stack and queue operations.

⚡

Lower overhead

ArrayDeque avoids Vector's legacy synchronization.

🧩

More flexible

The same interface supports LIFO and FIFO algorithms.

Old Approach
Stack
Modern Approach
Deque with ArrayDeque
Since JDK
6
Difficulty
Beginner
Stack to Deque and ArrayDeque
Available

Available since JDK 6 (December 2006)

Stack extends the legacy synchronized Vector class. Deque models stack operations directly, and ArrayDeque is the preferred general-purpose implementation for in-memory LIFO work.