Skip to main content

Stack

java.util.Stack

caution

Use ArrayDeque for using Stack :~


caution

Must Use ArrayDeque class to declare Stack as it contains all the methods of Stack and can also implement Queue as well.

  • Stack cannot use for_Each loop to traverse through its elements. Iterator class with its methods .hasNext() & .next() must be used to print and traverse through all its elements.
  • Stack uses Last In First Out (LIFO)
  • Stack can only use push() to add elements and pop() to remove and print elements and

Stack Methods

push()

pop()

peek()