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.