ArrayDeque in Java is a class belonging to the Java Collection framework. It extends the AbstractCollection class and implements the Deque, Cloneable, and Serializable interfaces.

The ArrayDeque class supplies the implementation of the Deque interface and offers a resizable array. It is also referred to as an Array Double Ended Queue, or Array Deck.
- Array deques expand automatically, so there are no capacity restrictions.
- Array deques are not thread-safe, which means ArrayDeque does not allow concurrent access by multiple threads.
- Null elements are not permitted in an ArrayDeque.
- The ArrayDeque class is faster than Stack and Deque.
Constructors of ArrayDeque in Java
- ArrayDeque(): This is the default constructor of the ArrayDeque class. It creates an empty ArrayDeque with an initial default capacity of 16.
- ArrayDeque(Collection<E> c): This constructor creates an ArrayDeque from the elements of the specified collection c.
- ArrayDeque(int initialCapacity): This constructor creates an empty ArrayDeque with the capacity you specify.
Methods of ArrayDeque in Java
- add(E e): Adds the given element to the Deque by appending it at the end. Its return type is boolean.
- addFirst(E e): Inserts the given element at the front of the Deque. Its return type is void.
- addLast(E e): Inserts the given element at the end of the Deque. Its return type is void.
- offer(E e): Adds the given element at the end of the Deque. Its return type is boolean.
- offerFirst(E e): Adds the given element at the front of the Deque. Its return type is boolean.
- offerLast(E e): Adds the given element at the end of the Deque. Its return type is boolean.
- push(): Pushes the given element onto the front of the Deque. Its return type is void.
- remove(): Removes and returns the first element of the Deque. Its return type is E.
- removeFirst(): Removes and returns the first element of the Deque. Its return type is E.
- removeLast(): Removes and returns the last element of the Deque. Its return type is E.
- removeFirstOccurrence(): Removes the first occurrence of the specified element from the Deque. Its return type is boolean.
- removeLastOccurrence(): Removes the last occurrence of the specified element from the Deque. Its return type is boolean.
- getFirst(): Returns the first element of the Deque. Its return type is E.
- getLast(): Returns the last element of the Deque. Its return type is E.
- peek(): Retrieves the first element of the Deque. Its return type is E.
- peekFirst(): Also retrieves the first element of the Deque. Its return type is E.
- peekLast(): Retrieves the last element of the Deque. Its return type is E.
- poll(): Removes and returns the first element of the Deque. Its return type is E.
- pollFirst(): Also removes and returns the first element of the Deque. Its return type is E.
- pollLast(): Removes and returns the last element of the Deque. Its return type is E.
- pop(): Also removes and returns the first element of the Deque. Its return type is E.
- element(): Returns the first element of the Deque without removing it from the list. Its return type is E.
- isEmpty(): Checks whether the Deque is empty or not. Its return type is boolean.
- clear(): Removes every element from the Deque. It returns nothing, so its return type is void.
- contains(Object o): Checks whether the given element is present in the ArrayList or not. Its return type is boolean.
- size(): Returns the number of elements currently present in the Deque.
- clone(): Returns a shallow copy of this Deque instance.
- iterator(): Returns an iterator over the elements of this Deque.
- descendingIterator(): Returns an iterator over the elements in descending order.
- Returns an array containing all of the elements of the ArrayList in the correct order.
// Java program to demonstrate few functions of
// ArrayDeque in Java
import java.util.ArrayDeque;
public class ExampleOfArrayDeque
{
public static void main(String[] args)
{
ArrayDeque<Integer> numbers = new ArrayDeque<Integer>(10);
numbers.add(10);
numbers.add(20);
numbers.add(30);
numbers.add(40);
numbers.add(50);
for (Integer element : numbers)
{
System.out.println("Element : " + element);
}
// remove() method : to get head
System.out.println("Head element remove : " + numbers.remove());
System.out.println("The final array is: "+numbers);
}
}
Output: Element : 10
Element : 20
Element : 30
Element : 40
Element : 50
Head element remove : 10
The final array is: [20, 30, 40, 50]

