Java stack class

Stack Class :

  • It is child class of vector
  • It is specially designed class for last in first out order(LIFO)


Stack s = new stack();


  • push(Object o)
  • pop() offset
  • peek()

java stack example
 //3 ;//-1




  • Object push(Object obj):-For inserting an object to the stack.
  • Object pop():-To removes and returns top of the stack.
  • Object peek():-To returns the top of the stack without removal of the object.
  • int search(Object obj):-If the specified object is available it returns its offset from the top of the stack. If the object is not available then it returns -1.
  • Object top():- For inserting an object to the stack.

Example of stack:

Output :

[A, B, C]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.