VOOZH about

URL: https://www.geeksforgeeks.org/java/copyonwritearraylist-containsall-method-in-java/

⇱ CopyOnWriteArrayList containsAll() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CopyOnWriteArrayList containsAll() method in Java

Last Updated : 17 Dec, 2018
The containsAll() method of CopyOnWriteArrayList class 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 illustrate the containsAll() method of CopyOnWriteArrayList class: Program 1:
Output:
CopyOnWriteArrayList1: [geeks, shaan, gfg, programming]
CopyOnWriteArrayList2: [geeks, gfg]
All list2 elements are present in list1
CopyOnWriteArrayList3: [geeks, qwe]
All list3 elements are not present in list1
Program 2:
Output:
CopyOnWriteArrayList1: [23, 65, 91, 126]
CopyOnWriteArrayList2: [23, 126]
All list2 elements are present in list1
CopyOnWriteArrayList3: [23, 92]
All list3 elements are not present in list1
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CopyOnWriteArrayList.html#containsAll(java.util.Collection)
Comment
Article Tags:
Article Tags: