VOOZH about

URL: https://www.geeksforgeeks.org/java/list-containsall-method-in-java-with-examples/

⇱ List containsAll() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

List containsAll() method in Java with Examples

Last Updated : 11 Dec, 2018
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:
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)
Comment