Java containsAll() method

The purpose of this containsAll() is to check whether a collection contains all the elements present in another collection or the mentioned collection or not.

Syntax of containsAll()

boolean containsAll(Collection<?> obj)

Parameters: It takes a Collection object as a parameter which is to be checked with the current collection.

return type: It returns boolean (either `true` or `false`)

true: if the collection object contains all the elements as in the current collection.
false: if the collection object elements don’t match with the current collection elements (if there is a single mismatch, it returns false).

The number of elements in the current collection object and the compared collection object need not be the same.

Java Collection containsAll() Method with Examples

The Collection interface in Java is the fundamental part of the Collection hierarchy. It is found in the java.util package and offers a wide range of built-in classes and methods. One such useful method is containsAll().

Similar Reads

Java containsAll() method

The purpose of this containsAll() is to check whether a collection contains all the elements present in another collection or the mentioned collection or not....

Example of Java containsAll() method

Java containsAll() method can be implemented with any collection some of them are mentioned with example bellow....

Contact Us