Stack is like a bucket we you can enter objects and retrieve
it. Here in the example describes the methods to prepare an
example of Java stack program. The
Stack class represents a last-in-first-out (LIFO) stack of
objects. It extends class Vector and implements Cloneable, Collection, List, Serializable
interfaces. We mostly use push and
In this example we are using two methods of Stack.
push(Object item): It pushes an item onto the top of this stack.
pop(): Removes the object from the top of this stack and returns that object as the value of this function. It throws EmptyStackException if the stack is empty.
Code of the program is given below
Output of this example is given below:
|The contents of Stack is[10, a]
The size of an Stack is2
The number poped out isa
The number poped out is 10
The contents of stack is
The size of an stack is0
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: June 7, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles