Java Stack class extends Vector class and both belongs to java.util package.
It orders the element in LIFO(Last In First Out) manner. The best example stack of plates
LIFO : This means insertion and deletion will always be happening from same side.
Stack<T> stack = new Stack<T>();
Below is the example for some of the methods which allow us to add, peak, contains, pop, firstElement, lastElement and indexOf items from Stack.
Note: I always try to make things easy and simple, please read comments while reading code snippet will help to understand better.
OUTPUT:
Below is the example for some of the methods which allow us to add, push, addElement, elementAt, remove, reomoveAllElements and search items from stack.
Note: I always try to make things easy and simple, please read comments while reading code snippet will help to understand better.
OUTPUT:
Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.
📝 Blogs
javadoubts.com © All rights reserved