The Java.util.Stack.remove(int index) method is used to remove an element from a Stack from a specific position or index.
Parameters: This method accepts a mandatory parameter index is of integer data type and specifies the position of the element to be removed from the Stack.
Return Value: This method returns the element that has just been removed from the Stack.
Below program illustrate the Java.util.Stack.remove(int index) method:
Stack: [Geeks, for, Geeks, 10, 20] Removed element: 20 Final Stack: [Geeks, for, Geeks, 10]
Stack: [10, 20, 30, 40, 50] Removed element: 10 Final Stack: [20, 30, 40, 50]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.