Stack Java

Stack Introduction and Implementation in Java

Stack is more abstract entity than array and many other data structures. The underlying mechanism used to implement stacks is not visible to the user.

It follows Last In First Out (LIFO) principle i.e., stacks allows access to only one data item at a time, that is inserted last. If you remove the last item then you can access the next item that is next to that last item inserted.

Stack operations

  • Push – Adds an item to the collection.
  • Pop – Removes the most recently added item from the collection.

Applications of stack

  • Most microprocessor uses stack based architecture. The stack operations are built into the microprocessor.
  • Old pocket calculators used stack based architecture.

Stack Implementation in Java

The following program implements a stack in java using a class called MyStack.


Recommended Posts


Leave a Reply

Notify of