Implement Stack using Array in java

If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions.

In this post, we will see how to implement Stack using Array in java.
Stack is abstract data type which demonstrates Last in first out (LIFO) behavior. We will implement same behavior using Array.
Although java provides implementation for all abstract data types such as Stack,Queue and LinkedList but it is always good idea to understand basic data structures and implement them yourself.
Please note that Array implementation of Stack is not dynamic in nature. You can implement Stack through linked list for dynamic behavior.

Java Program to implement Stack using Array:

When you run above program, you will get below output:

As you can see we have pushed 40 in last, so it is popped first as Stack is of Last In First Out(LIFO) nature.

Add Comment