

We can make a stack of String datatype, of Integer datatype, or Character datatype. It enables the user to use any data type. We name our class as ArrayStack as we are using Array to store our data.Į in Angular brackets () makes our class Generic. It will have the same functionality as we saw in the above examples. We are implementing our own stack using class and methods. Implementation of Stack Using Array in Java You must have also observed the Back and Forward buttons on browsers. When you make changes, it pushes changes onto the stack.

When you undo something, it pops the most recent action. One such application is undo mechanism in text editors.

No element can be retrived, removed, or added from the middle of the stack. In a like manner, elements can be added to the stack at the top and they can be seen or removed from the top. We cannot add or remove a plate at the middle of the stack. So, when we need a plate, we take (pop) from the top of the stack and when we want to add a plate we put (push) it at the top as well. The name “stack” is derived from a stack of plates.
