Push in and pop up a Stack

 
import java.util.Stack;

public class Stacks {

  public static void main(String[] args) {
    Stack stack = new Stack();
    for (int i = 0; i < 10; i++)
      stack.push(new Integer(i));
    System.out.println("stack = " + stack);
    
    
    stack.addElement("The last line");
    System.out.println("element 5 = " + stack.elementAt(5));
    System.out.println("popping elements:");
    while (!stack.empty())
      System.out.println(stack.pop());
  }
}
  
Home 
  Java Book 
    Runnable examples  

Collection Stack:
  1. Peek and search a Stack
  2. Push in and pop up a Stack