I Help You
Programming

Stack

A stack is a linear data structure that follows the LIFO (Last In, First Out) principle: the element added last is the first one removed. Elements are added with a push operation and removed with a pop operation, both at the same end, called the top.

Stacks are used for function calls (the call stack), undo features, expression evaluation, matching brackets and backtracking algorithms.

Example
import java.util.ArrayDeque;
import java.util.Deque;

Deque<Integer> stack = new ArrayDeque<>();
stack.push(1);
stack.push(2);
stack.push(3);
System.out.println(stack.pop());  // 3 (last in, first out)
System.out.println(stack.peek()); // 2