Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Stack

public class Stack
extends Vector<E>

java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.AbstractList<E>
       ↳ java.util.Vector<E>
         ↳ java.util.Stack<E>


Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables users to pop to and push from the stack, including null objects. There is no limit to the size of the stack.

Summary

Inherited fields

From class java.util.Vector
From class java.util.AbstractList

Public constructors

Stack()

Constructs a stack with the default size of Vector.

Public methods

boolean empty()

Returns whether the stack is empty or not.

E peek()

Returns the element at the top of the stack without removing it.

E pop()

Returns the element at the top of the stack and removes it.

E push(E object)

Pushes the specified object onto the top of the stack.

int search(Object o)

Returns the index of the first occurrence of the object, starting from the top of the stack.

Inherited methods

From class java.util.Vector
From class java.util.AbstractList
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.util.List
From interface java.util.Collection
From interface java.lang.Iterable

Public constructors

Stack

Added in API level 1
Stack ()

Constructs a stack with the default size of Vector.

Public methods

empty

Added in API level 1
boolean empty ()

Returns whether the stack is empty or not.

Returns
boolean true if the stack is empty, false otherwise.

peek

Added in API level 1
E peek ()

Returns the element at the top of the stack without removing it.

Returns
E the element at the top of the stack.
Throws
EmptyStackException if the stack is empty.

See also:

pop

Added in API level 1
E pop ()

Returns the element at the top of the stack and removes it.

Returns
E the element at the top of the stack.
Throws
EmptyStackException if the stack is empty.

See also:

push

Added in API level 1
E push (E object)

Pushes the specified object onto the top of the stack.

Parameters
object E: The object to be added on top of the stack.
Returns
E the object argument.

See also:

search

Added in API level 1
int search (Object o)

Returns the index of the first occurrence of the object, starting from the top of the stack.

Parameters
o Object: the object to be searched.
Returns
int the index of the first occurrence of the object, assuming that the topmost object on the stack has a distance of one.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.