Java Program to Implement ArrayDeque API Last Updated : 19 Jan, 2021 Comments Improve Suggest changes Like Article Like Report The ArrayDeque in Java provides how to use resizable-array additionally to the implementation of the Deque interface. It is also referred to as Array Double Ended Queue or Array Deck. This is a special quite array that grows and allows users to feature or remove a component from each side of the queue. java.lang.Object java.util.AbstractCollection<E> java.util.ArrayDeque<E> All implemented interfaces of ArrayDeque in the hierarchy are: Serializable, Cloneable, Iterable<E>, Collection<E>Deque<E> Queue<E> Array deques haven't any capacity restrictions; they grow as necessary to support usage. They are not thread-safe; within the absence of external synchronization, they are doing not support concurrent access by multiple threads. Null elements are prohibited. This class is probably going to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue. Implementation: Java // Java program to demonstrate implementation // of ArrayDeque import java.util.*; public class ArrayDequeExample { public static void main(String[] args) { // Initializing an deque Deque<Integer> de_que = new ArrayDeque<Integer>(10); // add() method to insert de_que.add(10); de_que.add(20); de_que.add(30); de_que.add(40); de_que.add(50); for (Integer element : de_que) { System.out.println("Element : " + element); } System.out.println("Using clear() "); // clear() method de_que.clear(); // addFirst() method to insert at start de_que.addFirst(564); de_que.addFirst(291); // addLast() method to insert at end de_que.addLast(24); de_que.addLast(14); System.out.println( "Above elements have been cleared"); // Iterator() : System.out.println( "Elements of deque using Iterator :"); for (Iterator itr = de_que.iterator(); itr.hasNext();) { System.out.println(itr.next()); } // descendingIterator() : to reverse the deque order System.out.println( "Print elements in reverse order :"); for (Iterator dItr = de_que.descendingIterator(); dItr.hasNext();) { System.out.println(dItr.next()); } // element() method : to get Head element System.out.println( "\nHead Element using element(): " + de_que.element()); // getFirst() method : to get Head element System.out.println( "Getting Head Element using getFirst(): " + de_que.getFirst()); // getLast() method : to get last element System.out.println( "Getting Last Element using getLast(): " + de_que.getLast()); // toArray() method : Object[] arr = de_que.toArray(); System.out.println("\nArray Size : " + arr.length); System.out.print("Array elements : "); for (int i = 0; i < arr.length; i++) System.out.print(" " + arr[i]); // peek() method : to get head System.out.println("\nHead element : " + de_que.peek()); // poll() method : to get head System.out.println("Head element poll : " + de_que.poll()); // push() method : de_que.push(265); de_que.push(984); de_que.push(2365); // remove() method : to get head System.out.println("Head element remove : " + de_que.remove()); System.out.println("Final Array: " + de_que); } } OutputElement : 10 Element : 20 Element : 30 Element : 40 Element : 50 Using clear() Above elements have been cleared Elements of deque using Iterator : 291 564 24 14 Print elements in reverse order : 14 24 564 291 Head Element using element(): 291 Getting Head Element using getFirst(): 291 Getting Last Element using getLast(): 14 Array Size : 4 Array elements : 291 564 24 14 Head element : 291 Head element poll : 291 Head element remove : 2365 Final Array: [984, 265, 564, 24, 14] Comment More infoAdvertise with us Next Article Java Program to Implement ArrayDeque API M mayanktyagi1709 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Collections Java-ArrayDeque +2 More Practice Tags : JavaJava-Collections Similar Reads Java Program to Implement ArrayBlockingQueue API ArrayBlockingQueue class is a member of the Java Collection framework. ArrayBlockingQueue is a bounded blocking queue. The term bounded, means that the size of the Queue is fixed and cannot be changed. Any attempt to put element/elements into a full queue will lead to blocking operation. Similarly, 7 min read Java Program to Implement ConcurrentLinkedDeque API ConcurrentLinkedDeque class in Java is an unbounded concurrent deque that stores its elements as linked nodes where each node contains the address of the previous as well as next nodes. It belongs to java.util.concurrent package. This class is a member of the Java Collections Framework. It also exte 3 min read Java Program to Implement ConcurrentLinkedQueue API The ConcurrentLinkedQueue class in Java is a part of the Java Collection Framework. It belongs to java.util.concurrent package. It was introduced in JDK 1.5. It is used to implement Queue with the help of LinkedList concurrently. It is an unbounded thread-safe implementation of Queue which inserts e 4 min read Java Program to Implement PriorityQueue API A PriorityQueue is a linear data structure in which the elements are ordered according to their natural ordering or by some custom comparator provided at the queue at construction time. In PriorityQueue, the front of the queue points to the least element, and the rear points to the greatest element 4 min read Java Program to Change a Collection to an Array An array is a data structure that can hold a fixed-size, homogeneous collection of elements of the same data type, which can be either primitive data types (e.g., int, float) or object references. However, the size of the array cannot be changed once it is created. On the other hand, a collection is 3 min read Like