Stack removeElementAt() method in Java with Example
The Java.util.Stack.removeElementAt(int index) method is used to remove an element from a Stack from a specific position or index. In this process the size of the Stack is automatically reduced by one and all other elements after the removed element are shifted downwards by one position.
Parameters: This method accepts a mandatory parameter index of integer data type which specifies the position of the element to be removed from the Stack.
Return Value: This method has void return type. It means it does not return anything.
Below program illustrate the Java.util.Stack.remove(int index) method:
Stack: [Geeks, for, Geeks, 10, 20] The initial size is: 5 Final Stack: [Geeks, for, 10, 20] The final size is: 4
Stack: [10, 20, 30, 40, 50] The initial size is: 5 Final Stack: [20, 30, 40, 50] The final size is: 4
My Personal Notes arrow_drop_up
Please Login to comment...