- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
The Stack class in Java is a part of the Java Collection Framework and represents a last-in-first-out (LIFO) stack of objects. It extends the Vector class and provides several methods to perform standard stack operations such as push, pop, peek, empty, and search.
Key Methods of Stack Class
1. push(E item)
The push method adds an item to the top of the stack. This method is equivalent to the addElement method of the Vector class.
Stack<Integer> stack = new Stack<>();stack.push(1);stack.push(2);System.out.println(stack); // Output: [1, 2]Copied!✕Copy2. pop()
The pop method removes and returns the object at the top of the stack. If the stack is empty, it throws an EmptyStackException.
int topElement = stack.pop();System.out.println(topElement); // Output: 2System.out.println(stack); // Output: [1]Copied!✕Copy3. peek()
The peek method returns the object at the top of the stack without removing it. If the stack is empty, it throws an EmptyStackException.
Stack (Java Platform SE 8 ) - Oracle
The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack.
See results only from docs.oracle.comOverview
Java™ Platform, Standard Edition 8 API Specification This document is the API …
EmptyStackException
Methods inherited from class java.lang. Throwable addSuppressed, …
Java Se 21 & JDK 21
The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class …
Stack
We would like to show you a description here but the site won’t allow us.
Splittablerandom
A generator of uniform pseudorandom values applicable for use in (among other …
Deque
Note that the peek method works equally well when a deque is used as a queue or …
Object
The Java programming language does not guarantee which thread will invoke the …
All Classes
This page provides a comprehensive list of all classes in the Java Platform SE 8 API …
AbstractList
The number of times this list has been structurally modified. Structural …
Vector
As of the Java 2 platform v1.2, this class was retrofitted to implement the List …
Stack Class in Java - GeeksforGeeks
Mar 23, 2026 · In Java, a Stack is a linear data structure that follows the Last In First Out (LIFO) principle and is defined in the java.util package. Internally, it …
Quick Guide to Java Stack | Baeldung
- This tutorial is a quick and practical guide to understand this core class in Java – the Stack. Of course, you can explore the full API in the Javadoc. And, as always, all code samples can be found over on GitHub.
- Published: Dec 21, 2019
Java Stack Class - Programiz
In this tutorial, we will learn about the Java Stack class and its methods with the help of examples.
Java Stack Tutorial: Stack Class Implementation With Examples
Java Stack class - Tpoint Tech
Feb 13, 2026 · The stack is a linear data structure that is used to store the collection of objects. It is based on Last-In-First-Out (LIFO).
Java - The Stack Class - Online Tutorials Library
Stack is a subclass of Vector that implements a standard last-in, first-out stack. Stack only defines the default constructor, which creates an empty stack. Stack includes all the methods defined by Vector, …
Stack.java - Princeton University
Nov 26, 2022 · Below is the syntax highlighted version of Stack.java from §4.3 Stacks and Queues. /****************************************************************************** * Compilation: javac …
Java | Stack | Codecademy
Nov 21, 2022 · A stack in Java represents a last-in, first-out (LIFO) data structure for storing objects. It is implemented as the Stack class within the java.util package …
Java Stack - Jenkov.com
May 21, 2020 · The Java Stack class is a classical stack data structure, where elements can be pushed onto the top of the stack, and popped off the top again. …