Stack removeAll() method in Java with Example
The Java.util.Stack.removeAll(Collection col) method is used to remove all the elements from the Stack, present in the collection specified.
Parameters: This method accepts a mandatory parameter col which is the collection whose elements are to be removed from the Stack.
Return Value: This method returns true if the Stack is altered due to the operation at all, else False.
Exception: The method throws NullPointerException if the specified collection is null.
Below programs illustrate the Java.util.Stack.removeAll(Collection col) method:
Stack: [Geeks, for, Geeks, 10, 20] Collection removed Final Stack: [10, 20]
Stack: [1, 2, 3, 10, 20] Collection not removed Final Stack: [1, 2, 3, 10, 20]
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.