java.util
Class Stack<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<T>
          extended by java.util.Vector<T>
              extended by java.util.Stack<T>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess

public class Stack<T>
extends Vector<T>

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Stack()
          This constructor creates a new Stack, initially empty
 
Method Summary
 boolean empty()
          Tests if the stack is empty.
 T peek()
          Returns the top Object on the stack without removing it.
 T pop()
          Pops an item from the stack and returns it.
 T push(T item)
          Pushes an Object onto the top of the stack.
 int search(Object o)
          Returns the position of an Object on the stack, with the top most Object being at position 1, and each Object deeper in the stack at depth + 1.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

Stack

public Stack()
This constructor creates a new Stack, initially empty

Method Detail

push

public T push(T item)
Pushes an Object onto the top of the stack. This method is effectively the same as addElement(item).

Parameters:
item - the Object to push onto the stack
Returns:
the Object pushed onto the stack
See Also:
Vector.addElement(Object)

pop

public T pop()
Pops an item from the stack and returns it. The item popped is removed from the Stack.

Returns:
the Object popped from the stack
Throws:
EmptyStackException - if the stack is empty

peek

public T peek()
Returns the top Object on the stack without removing it.

Returns:
the top Object on the stack
Throws:
EmptyStackException - if the stack is empty

empty

public boolean empty()
Tests if the stack is empty.

Returns:
true if the stack contains no items, false otherwise

search

public int search(Object o)
Returns the position of an Object on the stack, with the top most Object being at position 1, and each Object deeper in the stack at depth + 1.

Parameters:
o - The object to search for
Returns:
The 1 based depth of the Object, or -1 if the Object is not on the stack