The removeAll() method of ArrayDeque is used to remove all the elements which is common in both ArrayDeque and the collection passed as parameter. This method first collect all the elements of Collection and then starts removing the elements from ArrayDeque which are same as elements of Collection.After this method execution, this ArrayDequeu will contain no elements in common with the collection. This methods True if this ArrayDeque changed as a result of the calling this method.
public boolean removeAll(Collection<? extends E> col)
Parameter: This method takes a parameter c which represents Collection of the elements we want to remove from this deque.
Returns: This method returns True if this deque changed as a result of the calling this method.
Exception: This method throws NullPointerException if the specified collection or any of its elements are null.
Below programs illustrate removeAll() method of ArrayDeque:
Program 1: Program to demonstrate removeAll() method on ArrayDeque which going to remove elements same as elements from a collection containing Numbers.
Before calling removeAll() 23 32 45 63 After calling removeAll() 23 32
Program 2: Program to demonstrate removeAll() method on ArrayDeque which going to remove elements same as elements from collection of Students Names.
Before calling removeAll() List of Students Name: | Ram | | Mohan | | Sohan | | Rabi | After calling removeAll() List of Students Name: | Ram | | Mohan |
Program 3: Program to demonstrate Exception thrown by removeAll() method.
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.