What does the method pop() do in java?

Java 8Object Oriented ProgrammingProgramming

The pop() method is used to remove the object at the top of this stack and returns that object as the value of this function.

Example

import java.util.*;

public class StackDemo {
   public static void main(String args[]) {
      Stack st = new Stack();
      st.push("Java");
      st.push("Source");
      st.push("code");
      System.out.println("Removed object is: "+st.pop());
      System.out.println("Elements after remove: "+st);
   }
}

Output

Removed object is: code
Elements after remove: [Java, Source]
raja
Published on 08-Feb-2018 13:24:35
Advertisements