Java Collection containsAll() MethodThe containsAll() method of Java Collection Interface returns a Boolean value 'true', if this collection contains all the elements in the invoked collection. SyntaxParametersThe parameter 'c' represents the collection to be checked for occurrence in this collection. ThrowsClassCastException- if the types of the elements in the specified collection are not compatible with this collection. NullPointerException- if the specified collection is null or it contains one or more null elementsl and this collection does not allow null elements. ReturnThe containsAll() method returns Boolean value 'true' if this collection contains all of the elements in the invoked collection, else it returns false. Example 1Test it NowOutput: true Example 2Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.util.ArrayDeque.addLast(ArrayDeque.java:249) at java.util.ArrayDeque.add(ArrayDeque.java:423) at com.javaTpoint.JavaCollectionContainsAllExample2.main(JavaCollectionContainsAllExample2.java:13) Example 3Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.util.AbstractCollection.containsAll(AbstractCollection.java:317) at com.javaTpoint.JavaCollectionContainsAllExample3.main(JavaCollectionContainsAllExample3.java:14) Next TopicJava Collection |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India