CodesJava

Easy learning with example program codes

Java Stack tutorial


A stack is an ADT – Abstract Data Type or a linear data structure. It is a LIFO data structure because it allows all data operations at one end only i.e. elements can be added and removed from the stack only at the top. LIFO stands for Last-in-first-out. The element which is inserted last, is accessed first.

Stack operations

  • push(): Pushing an element on the stack.
  • pop(): Removing an element from the stack.
  • peek(): Get the top data element of the stack, without removing it.
  • isFull(): Check if stack is full.
  • isEmpty(): Check if stack is empty.

Stack states

Overflow state: A stack is in overflow state if it does not contain enough space to accept an entity to be pushed.
Underflow state: A stack is in underflow state if we want to operate stack with pop operation and the stack is empty.

Stacks efficiency

As we discussed, all operations are done at the top of the stack so no comparisons or moves of elements are necessary. Hence it is very fast.

Java stack examples

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki