Java List containsAll() MethodThe containsAll() method of List interface returns a Boolean value 'true' if this list contains all the elements of the invoked collection. SyntaxParametersThe parameter 'c' represents the collection to be checked for occurrence in this list. Specified BycontainsAll in interface Collection<E> Throws:ClassCastException- If the types of one or more elements in the specified collection are not compatible with this list. NullPointerException- If the specified collection is null or it contains one or more null elements, and this list does not allow null elements. Returns:The containsAll() method returns Boolean value 'true' if this list contains all the elements in the invoked collection, else it returns false. Example 1Test it NowOutput: Total elements in the list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Contains All method will return true Example 2Test it NowOutput: Total elements in the list : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Exception in thread "main" java.lang.NullPointerException at java.util.AbstractCollection.containsAll(AbstractCollection.java:317) at com.javaTpoint.JavaListContainsAllExample2.main(JavaListContainsAllExample2.java:13) Example 3Test it NowOutput: Total elements in the list : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Total elements in the list1 : [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0] Contains All method will return false Next TopicJava List |
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