java tutorial - Java Deque Interface - java programming - learn java - java basics - java for beginners
Java Deque Interface is a linear collection that supports element insertion and removal at both ends. Deque is an acronym for "double ended queue".
Deque Interface declaration
Methods of Java Deque Interface
|boolean add(object)||It is used to insert the specified element into this deque and return true upon success.|
|boolean offer(object)||It is used to insert the specified element into this deque.|
|Object remove()||It is used to retrieves and removes the head of this deque.|
|Object poll()||It is used to retrieves and removes the head of this deque, or returns null if this deque is empty.|
|Object element()||It is used to retrieves, but does not remove, the head of this deque.|
|Object peek()||It is used to retrieves, but does not remove, the head of this deque, or returns null if this deque is empty.|
The ArrayDeque class provides the facility of using deque and resizable-array. It inherits AbstractCollection class and implements the Deque interface.
The important points about ArrayDeque class are:
- Unlike Queue, we can add or remove elements from both sides.
- Null elements are not allowed in the ArrayDeque.
- ArrayDeque is not thread safe, in the absence of external synchronization.
- ArrayDeque has no capacity restrictions.
- ArrayDeque is faster than LinkedList and Stack.
- The hierarchy of ArrayDeque class is given in the figure displayed at the right side of the page.
Learn java - java tutorial - array-deque - java examples - java programs
ArrayDeque class declaration
Let's see the declaration for java.util.ArrayDeque class.