22.20 Stacks

Stacks

Overview

A Stack is a LIFO (Last In, First Out) data structure where elements are added and removed from the top.

Topics

Examples

import java.util.Stack;

Stack<Integer> stack = new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);

System.out.println("Popped: " + stack.pop());
System.out.println("Top: " + stack.peek());

Tags

#java #stack #datastructures #lifo