Головна‎ > ‎Java‎ > ‎Додатково‎ > ‎

Стек

import java.util.Stack;

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

System.out.println("All: " + stack);
System.out.println("Pop: " + stack.pop());
System.out.println("Pop: " + stack.pop());
System.out.println("Pop: " + stack.pop());
System.out.println("All: " + stack);


All: [1, 2, 3, 4]
Pop: 4
Pop: 3
Pop: 2
All: [1]