Deque: push(T e) : Deque « java.util « Java by API






Deque: push(T e)

 

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() + " ");
  }
}

   
  








Related examples in the same category

1.Deque: isEmpty()
2.Deque: peekFirst()
3.Deque: pop()
4.Deque: remove()
5.Deque: removeFirst()