Java Stack - Smart Tech Guides

Latest

Hi this is Sravan Kumar from India. SMART TECH GUIDES is a technical blog. it helps you to learn about Java topics, frameworks and tools like Jenkins, GitHub & related explanations, data base related topics. All these Explanations are explained in simple and understandable manner.

Subscribe Us

SMART TECH GUIDES

Java Stack

 

Stack:(List interface)

Stack Class Is part of collection framework and it is available in “java.util” package.

The Stack class extends the Vector class.

In stack, elements are stored and accessed in LIFO manner last-in-first-out i.e., elements are added to the top of the stack and removed from the top of the stack.

To add an element to the top of the stack, we use the push() method.

To remove an element from the top of the stack, we use the pop() method.

The peek() method returns an object from the top of the stack.


Creation of Stack:

Stack st=new Stack( );


Java Code:


Output:

No comments:

Post a Comment