Java Stack

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.

Syntax:

Stack<T> stack = new Stack<T>();

add, peak, contains, pop, firstElement, lastElement and indexOf methods:

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:

add, push, addElement, elementAt, remove, reomoveAllElements and search stack Methods: 

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:

Imran Khan

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.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan