Packages  This Package  Prev  Next  Index  

§3.8 Class Stack

public  class  java.util.Stack
    extends  java.util.Vector  (I-§3.10)
{
        // Constructors
    public Stack();	§3.8.1

        // Methods
    public boolean empty();	§3.8.2
    public Object peek();	§3.8.3
    public Object pop();	§3.8.4
    public Object push(Object  item);	§3.8.5
    public int search(Object  o);	§3.8.6
}
The Stack class represents a last-in-first-out (LIFO) stack of objects.


Constructors

Stack

public Stack()
Creates a new stack with no elements.

Methods

empty

public boolean empty()
Returns:
true if this stack is empty; false otherwise.

peek

public Object peek()
Looks at the object at the top of this stack without removing it from the stack.
Returns:
the object at the top of this stack.
Throws
EmptyStackException (I-§3.13)
If this stack is empty.

pop

public Object pop()
Removes the object at the top of this stack and returns that object as the value of this function.
Returns:
The object at the top of this stack.
Throws
EmptyStackException (I-§3.13)
If this stack is empty.

push

public Object push(Object item)
Pushes an item onto the top of this stack.
Parameters:
item - the item to be pushed onto this stack.
Returns:
the item argument.

search

public int search(Object o)
Determines if an object is on this stack.
Parameters:
o - the desired object
Returns:
The distance from the top of the stack that at which the object is located at; the return value -1 indicates that the object is not on the stack.

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com