Stack pop() Method in Java Last Updated : 12 Dec, 2021 Comments Improve Suggest changes 12 Likes Like Report The Java.util.Stack.pop() method in Java is used to pop an element from the stack. The element is popped from the top of the stack and is removed from the same.Syntax: STACK.pop() Parameters: The method does not take any parameters.Return Value: This method returns the element present at the top of the stack and then removes it.Exceptions: The method throws EmptyStackException is thrown if the stack is empty.Below programs illustrate the Java.util.Stack.pop() method: Program 1: Java // Java code to illustrate pop() import java.util.*; public class StackDemo { public static void main(String args[]) { // Creating an empty Stack Stack<String> STACK = new Stack<String>(); // Use add() method to add elements STACK.push("Welcome"); STACK.push("To"); STACK.push("Geeks"); STACK.push("For"); STACK.push("Geeks"); // Displaying the Stack System.out.println("Initial Stack: " + STACK); // Removing elements using pop() method System.out.println("Popped element: " + STACK.pop()); System.out.println("Popped element: " + STACK.pop()); // Displaying the Stack after pop operation System.out.println("Stack after pop operation " + STACK); } } Program 2: Java // Java code to illustrate pop() import java.util.*; public class StackDemo { public static void main(String args[]) { // Creating an empty Stack Stack<Integer> STACK = new Stack<Integer>(); // Use add() method to add elements STACK.push(10); STACK.push(15); STACK.push(30); STACK.push(20); STACK.push(5); // Displaying the Stack System.out.println("Initial Stack: " + STACK); // Removing elements using pop() method System.out.println("Popped element: " + STACK.pop()); System.out.println("Popped element: " + STACK.pop()); // Displaying the Stack after pop operation System.out.println("Stack after pop operation " + STACK); } } Output: Initial Stack: [10, 15, 30, 20, 5] Popped element: 5 Popped element: 20 Stack after pop operation [10, 15, 30] Comment C chinmoy lenka Follow 12 Improve C chinmoy lenka Follow 12 Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-Stack +2 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like