Deque<Integer> arrayQueue = new ArrayDeque<>();
Deque<Integer> linkedListQueue = new LinkedList<>();
// these operations are useful and same on both.
arrayQueue.push()/addFirst()/addLast();
arrayQueue.remove()/removeFirst()/removeLast()/pop();
arrayQueue.peek()/peekFirst()/peekLast()/size()/
// Java program to demonstrate the
// iteration of elements in deque
import java.util.*;
public class ArrayDequeDemo {
public static void main(String[] args)
{
// Initializing an deque
Deque<String> dq
= new ArrayDeque<String>();
// add() method to insert
dq.add("For");
dq.addFirst("Geeks");
dq.addLast("Geeks");
dq.add("is so good");
for (Iterator itr = dq.iterator();
itr.hasNext();) {
System.out.print(itr.next() + " ");
}
System.out.println();
for (Iterator itr = dq.descendingIterator();
itr.hasNext();) {
System.out.print(itr.next() + " ");
}
}
}
// Array implementation of Deque
Deque<String> animal1 = new ArrayDeque<>();
// LinkedList implementation of Deque
Deque<String> animal2 = new LinkedList<>();