All Packages Class Hierarchy This Package Previous Next Index
Class java.util.Stack
java.lang.Object
|
+----java.util.Vector
|
+----java.util.Stack
- public class Stack
- extends Vector
The Stack
class represents a last-in-first-out
(LIFO) stack of objects.
-
Stack()
-
-
empty()
- Tests if this stack is empty.
-
peek()
- Looks at the object at the top of this stack without removing it
from the stack.
-
pop()
- Removes the object at the top of this stack and returns that
object as the value of this function.
-
push(Object)
- Pushes an item onto the top of this stack.
-
search(Object)
- Returns where an object is on this stack.
Stack
public Stack()
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.
pop
public synchronized 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
- if this stack is empty.
peek
public synchronized 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
- if this stack is empty.
empty
public boolean empty()
- Tests if this stack is empty.
- Returns:
-
true
if this stack is empty;
false
otherwise.
search
public synchronized int search(Object o)
- Returns where an object is on this stack.
- Parameters:
- o - the desired object.
- Returns:
- the distance from the top of the stack where the object is]
located; the return value
-1
indicates that the
object is not on the stack.
All Packages Class Hierarchy This Package Previous Next Index