The containsAll() method of List interface in Java is used to check if this List contains all of the elements in the specified Collection. So basically it is used to check if a List contains a set of elements or not.
Syntax:
boolean containsAll(Collection col)
Parameters: This method accepts a mandatory parameter
col which is of the type of collection. This is the collection whose elements are needed to be checked if it is present in the List or not.
Return Value: The method returns
True if all elements in the collection
col are present in the List otherwise it returns
False.
Exception: The method throws
NullPointerException if the specified collection is NULL.
Below programs illustrates the containsAll() method:
Program 1:
Output:
List: [Welcome, To, Geeks, 4, Geeks]
Are all the contents equal? true
Program 2: