Package java.util Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Stack

Constructors , Methods

public  class  java.util.Stack
    extends  java.util.Vector  
{
        // Constructors
    public Stack();	

        // Methods
    public boolean empty();	
    public Object peek();	
    public Object pop();	
    public Object push(Object  item);	
    public int search(Object  o);	
}

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() 

Return Value:

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.

Return Value:

Returns the object at the top of this stack.

Throw:

EmptyStackException

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.

Return Value:

Returns The object at the top of this stack.

Throw:

EmptyStackException

If this stack is empty.


push

public Object push(Object  item) 

Pushes an item onto the top of this stack.

Return Value:

Returns the item argument.

ParameterDescription
item the item to be pushed onto this stack.


search

public int search(Object  o) 

Determines if an object is on this stack.

Return Value:

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.

ParameterDescription
o the desired object



Top© 1996 Sun Microsystems, Inc. All rights reserved.