Java Stack.pop()

Syntax

Stack.pop() has the following syntax.

public E pop()

Example

In the following code shows how to use Stack.pop() method.


/*  ww w .  j a v a 2s .  com*/
import java.util.Stack;

public class Main {
   public static void main(String args[]) {
      
      Stack st = new Stack();
      
      st.push("Java");
      st.push("Source");
      st.push("from java2s.com");
      
      // removing top object
      System.out.println("Removed object is: "+st.pop());
      
      // elements after remove
      System.out.println("Elements after remove: "+st);
   }    
}

The code above generates the following result.