The following example shows how to empty the Stack and handle EmptyStackException.
Stack provides the following APIs,
public E push(E paramE)
- Pushes an element onto the top of stack.
public synchronized E pop()
- Removes the element at top of stack. Throws 'EmptyStackException' if Stack is empty.
public synchronized E peek()
- Returns the object at top of stack without remove it from stack.
Throws 'EmptyStackException' if Stack is empty.
public boolean empty()
- Returns true if the stack is empty otherwise false.