Java ArrayList removeAll() Method

The removeAll() method of Java ArrayList class removes all the elements from a list that are contained in the specified collection.

Syntax:

Parameter:

"c": collection that contained elements to be removed from this list.

Return:

True if the original list changed as a result of this call.

Exception:

java.lang.NullPointerException: If the specified collection is null, or if the original list contains null elements and the specified collection does not permit null elements.

ClassCastException: if the class of an element of the original list is incompatible with the specified collection.

Example 1

Test it Now

Output:

[A, B, C, D, E]
[C, D, E]
true
[A, B]

Example 2

Test it Now

Output:

[A, B, C, D]

Example 3

Test it Now

Output:

null
[a, b]

Next TopicJava ArrayList




Latest Courses