Create a Stack and Queue using ArrayDeque. : Deque « Collections « Java Tutorial






import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
  public static void main(String args[]) {
    Deque<String> stack = new ArrayDeque<String>();
    Deque<String> queue = new ArrayDeque<String>();

    stack.push("A");
    stack.push("B");
    stack.push("C");
    stack.push("D");

    while (!stack.isEmpty())
      System.out.print(stack.pop() + " ");

    queue.add("A");
    queue.add("B");
    queue.add("C");
    queue.add("D");
    while (!queue.isEmpty())
      System.out.print(queue.remove() + " ");
  }
}








9.16.Deque
9.16.1.The Collections Framework New Types
9.16.2.Create a Stack and Queue using ArrayDeque.