![]() |
VOOZH | about |
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 ArrayDeque will contain no elements in common with the collection. This methods True if this ArrayDeque changed as a result of the calling this method. Syntax:
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.
java.lang.NullPointerException
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/ArrayDeque.html#removeAll(java.util.Collection)