Java.util.Stack Class

Java.util.Stack Class


The java.util.Stack class represents a last-in-first-out (LIFO) stack of objects.

  • When a stack is first created, it contains no items.
  • In this class, the last element inserted is accessed first.

Class declaration

Following is the declaration for java.util.Stack class:

public class Stack<E>
   extends Vector<E>

Class constructors

S.N.Constructor & Description

This constructor creates an empty stack.

Class methods

S.N.Method & Description
1boolean empty()

This method tests if this stack is empty.

2E peek()

This method looks at the object at the top of this stack without removing it from the stack.

3E pop()

This method removes the object at the top of this stack and returns that object as the value of this function.

4E push(E item)

This method pushes an item onto the top of this stack.

5int search(Object o)

This method returns the 1-based position where an object is on this stack.

Methods inherited

This class inherits methods from the following classes:

  • java.util.Vector
  • java.util.AbstractList
  • java.util.Object
  • java.util.List

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.