Why there is no stack interface in the collection framework?

Viewed 252

Why there is no stack interface in the collection framework in java? Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet). So, why not a stack interface?

2 Answers

Stack is a legacy class. A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations.

From java-doc,

Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class

Stack class diagram,enter image description here

I think because there is already a java.util.Stack class, they couldn't add a stack interface without causing a lot of confusion.

Related