Java Stack


  • Stack is a child class of the Vector and Implements List interface.
  • Stack stores a group of objects b using a mechanism called LIFO.
  • LIFO stands for Last in first out, it means the last inserted element deleted first.

Creation of Stack: 

Stack<E> s= new Stack<E>(); 


  • We can use all collection Methods.
  • We can also use legacy methods of Vector class like addElement(), removeElement(), setElementAt()...
 if we want to follow the LIFO mechanism we should use Stack methods like follows.

  • E push(E obj)
this method will add a new element to the Stack.
  • E pop()
this method deletes the top element available on Stack.
  • E peek()
this method just returns the top element available on Stack.


Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.