removeAll() method

removeAll() method: This removeAll Java method uses to remove all elements of a collection from another collection.

boolean removeAll(Collection<?> c);

Where, c is the collection which you want to remove from this collection.

return type:  Its return type is boolean. It can return either true or false.

How the removeAll() method can work: It removes all elements of a specified collection from this collection. There may be any collection that can contain one or more such collections, but it removes the only one which found first. It returns true if the collection is removed successfully but if the collection doesn’t exist it will return the false.

This removeAll java method can throw different types of exceptions:
ClassCastException, If the type of the given element is incompatible for the collection.
NullPointerException, If the specified element is null and this collection does not permit null elements.
UnsupportedOperationException, If remove operation is not allowed by this collection.

Leave a Comment