Stack is a class in Java that follows the LIFO (Last In, First Out) principle. This means the element that is added last is the first one to be removed.
Elements can be removed from a stack using the pop() method, which removes and returns the element at the top of the stack.
Example code:
Stack<Integer> stack = new Stack<>();
stack.push(3); // adding the values
stack.push(1);
stack.push(2);
stack.pop(); // removes 2
System.out.print(stack); // prints [3, 1]
sukanya meruva Answered question