Use the Stack class in Java : Queue « Collections « Java Tutorial






import java.util.Stack;

public class Main {
  public static void main(String[] args) {
    Stack<Integer> stack = new Stack<Integer>();

    for (int i = 0; i < 10; i++) {
      stack.push(i);
      System.out.print(i + " ");
    }
    System.out.println("");

    int position = stack.search(3);
    System.out.println("Search result position: " + position);

    System.out.println("Stack top: " + stack.peek());

    while (!stack.empty()) {
      System.out.print(stack.pop() + " ");
    }
  }
}








9.14.Queue
9.14.1.Convert a Queue to a List
9.14.2.Use the Stack class in Java
9.14.3.Create a queue using LinkedList class
9.14.4.Checking what item is first in line without removing it: element
9.14.5.A Priority Queue
9.14.6.Binary Heap Queue
9.14.7.Circular Queue
9.14.8.Synchronized Queue