List containsAll() method in Java with ExamplesThe 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: Attention reader! Dont 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. 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:
Output:
List: [10, 15, 30, 20, 5]
Are all the contents equal? true
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/List.html#containsAll(java.util.Collection)
Article Tags :
Java
Java-Collections Java-Functions java-list Practice Tags :
Java Java-Collections |