The Stack class is a subclass
of Vector that implements a
last-in-first-out (LIFO) object stack. The Stack
class uses the following methods to provide stack behavior:
- The push() method pushes
an object onto the top of the stack.
- The pop() method removes
and returns the top element from the stack. If the stack is empty, pop()
throws an EmptyStackException.
- The peek() method returns,
but does not remove, the top element from the stack. If the stack is empty,
peek() throws an EmptyStackException.
- The empty() method returns
true if and only if the stack
is empty.