데이터를 순서대로 쌓는 자료 구조
import java.util.Stack;
public class StackExample {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<>();
// push
stack.push(1);
stack.push(2);
stack.push(3);
// pop
int topElement = stack.pop(); // topElement will be 3
System.out.println("Popped: " + topElement);
// peek
int peekedElement = stack.peek(); // peekedElement will be 2
System.out.println("Peeked: " + peekedElement);
// isEmpty
boolean isEmpty = stack.isEmpty(); // isEmpty will be false
System.out.println("Is empty: " + isEmpty);
}
}