Java Stack

Опубликовано: 16 Ноябрь 2025
на канале: Jakob Jenkov
9,026
215

The Java Stack class represents a classic stack as you know it from an algorithms and data structures class. The Java Stack class thus works similarly to a stack of plates, where you can add plates to the top of the stack, and also remove plates from the top of the stack. This Java Stack tutorial explains the basics of how to use the Java Stack class. Note: You can also use a Java Deque as a stack. See links below to my Java Deque tutorial.

stack.push() : Add an element to the top of the stack
stack.pop() : Remove an element from the top of the stack

Chapters
0:00 Java Stack introduction
1:25 Java Stack is synchronized - consider using a Deque instead
1:56 Java Stack witih generic types
3:15 Peek at top element on a Java Stack
4:10 Search for an element in a Java Stack
5:48 Iterate elements of a Java Stack
8:03 Reverse elements of a Java List using a Java Stack
10:28 Use a Java Deque as a Java Stack

Java Deque tutorial - text
http://tutorials.jenkov.com/java-coll...
Java Deque tutorial - video
   • Java Deque  

Java Lambda Expressions tutorial - text
http://tutorials.jenkov.com/java/lamb...
Java Lambda Expressions tutorial - video
   • Java Lambda Expressions #1 - The Basics  

Java Streams API tutorial - text
http://tutorials.jenkov.com/java-func...
Java Streams API tutorial - video
   • Java Streams API #1 - The Basics