Java Stack pop() method removes the object at the top of this stack and returns that object as the value of this function.
/**
* @author lautturi.com
* Java example: Stack pop() method
*/
import java.util.*;
import java.util.regex.Pattern;
public class Lautturi {
public static void main(String[] args){
Stack<Character> stack = new Stack<Character>();
stack.push('A');
stack.push('B');
stack.push('C');
stack.push('D');
System.out.println(stack);
Character ch = stack.pop();
System.out.println("Element at top: " + ch);
System.out.println(stack);
}
}Sourcual.www:etturi.comoutput:
Stack:[A, B, C, D] Element at top: D Stack now:[A, B, C]