stack is the subclass of Vector which is dynamic in nature and its size goes on increasing as the elements are added to it. Stack class allows creating the pile of the elements where, last element added to the stack is taken out first. This is also referred to as Last in First Out (LIFO).

For a Stack class, elements are pushed onto the stack by calling push() method and elements are retrieved using pop() method. First element of the stack is indicated by calling peek() method, which only points the element at the top of the stack but does not remove it. The search() method determines the existence of an object on the stack and to get the specified element to the top it performs those many pop calls.
Stack program
class Test 
public static void main(String[] args) 
Stack s=new Stack(); 
Output :
[A, 10, aaa]
[A, 10]

We see you’re using an ad blocker.

Our website is made possible by displaying ads to our visitors.

Please help us continue to provide you with free. So please disabling your ad blocker.