Stack Class in Java
Java provides an inbuilt object type called Stack. It is a collection that is based on the last in first out (LIFO) principle. On Creation, a stack is empty.
It extends Vector class with five methods that allow a vector to be treated as a stack. The five methods are:
Object push(Object element) : Pushes an element on the top of the stack.
Object pop() : Removes and returns the top element of the stack. An ‘EmptyStackException’ exception is thrown if we call pop() when the invoking stack is empty.
Object peek( ) : Returns the element on the top of the stack, but does not remove it.
boolean empty() : It returns true if nothing is on t...
Share this highlighthttp://www.safaribooksonline.com/a/java-programming-interviews/14116950/