Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
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>

Class Overview

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

[Expand]
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.
synchronized E peek ()
Returns the element at the top of the stack without removing it.
synchronized 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.
synchronized int search ( Object o)
Returns the index of the first occurrence of the object, starting from the top of the stack.
[Expand]
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.lang.Iterable
From interface java.util.Collection
From interface java.util.List

Public Constructors

public Stack ()

Added in API level 1

Constructs a stack with the default size of Vector .

Public Methods

public boolean empty ()

Added in API level 1

Returns whether the stack is empty or not.

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

public synchronized E peek ()

Added in API level 1

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

Returns
  • the element at the top of the stack.
Throws
EmptyStackException if the stack is empty.
See Also

public synchronized E pop ()

Added in API level 1

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

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

public E push (E object)

Added in API level 1

Pushes the specified object onto the top of the stack.

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

public synchronized int search ( Object o)

Added in API level 1

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

Parameters
o the object to be searched.
Returns
  • the index of the first occurrence of the object, assuming that the topmost object on the stack has a distance of one.