Java Deque InterfaceThe interface called Deque is present in java.util package. It is the subtype of the interface queue. The Deque supports the addition as well as the removal of elements from both ends of the data structure. Therefore, a deque can be used as a stack or a queue. We know that the stack supports the Last In First Out (LIFO) operation, and the operation First In First Out is supported by a queue. As a deque supports both, either of the mentioned operations can be performed on it. Deque is an acronym for "double ended queue". Deque Interface declarationMethods of Java Deque Interface
![]() ArrayDeque classWe know that it is not possible to create an object of an interface in Java. Therefore, for instantiation, we need a class that implements the Deque interface, and that class is ArrayDeque. It grows and shrinks as per usage. It also inherits the AbstractCollection class. The important points about ArrayDeque class are:
ArrayDeque HierarchyThe hierarchy of ArrayDeque class is given in the figure displayed at the right side of the page. ArrayDeque class declarationLet's see the declaration for java.util.ArrayDeque class. Java ArrayDeque ExampleFileName: ArrayDequeExample.java Output: Ravi Vijay Ajay Java ArrayDeque Example: offerFirst() and pollLast()FileName: DequeExample.java Output: After offerFirst Traversal... jai arvind vimal mukul After pollLast() Traversal... jai arvind vimal Java ArrayDeque Example: BookFileName: ArrayDequeExample.java Output: 101 Let us C Yashwant Kanetkar BPB 8 102 Data Communications & Networking Forouzan Mc Graw Hill 4 103 Operating System Galvin Wiley 6
Next TopicJava Map Interface
|