Java Collection removeAll() MethodThe removeAll() method of Java Collection Interface only removes those elements of the Collection that are contained in the specified collection. SyntaxParametersHere, the parameter 'c' represents the collection which contains the elements to be removed from the invoked collection. Return Value:The removeAll () method returns a Boolean value 'true' if the collection has changed as a result of the call, else it returns 'false'. Throws:UnsupportedOperationException- if the removeAll method is not supported by this collection. ClassCastException- if the types of one or more elements in this collection are not compatible with the invoked collection. NullPointerException- if this collection is null or it contains one or more null elements and this collection does not allow null elements. Example 1Test it NowOutput: collection : [1, 2, 3, 4, 5, 6, 7, 8, 9] List of even numbers : [2, 4, 6, 8] Odd numbers : [1, 3, 5, 7, 9] Example 2Test it NowOutput: Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Table of 2 : [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] Example 3Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.ConcurrentLinkedQueue.checkNotNull(ConcurrentLinkedQueue.java:920) at java.util.concurrent.ConcurrentLinkedQueue.offer(ConcurrentLinkedQueue.java:327) at java.util.concurrent.ConcurrentLinkedQueue.add(ConcurrentLinkedQueue.java:297) at com.javaTpoint.JavaCollectionRemoveAllExample3.main(JavaCollectionRemoveAllExample3.java:13) 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