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.
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:
List: [Welcome, To, Geeks, 4, Geeks] Are all the contents equal? true
List: [10, 15, 30, 20, 5] Are all the contents equal? true
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.