Java ConcurrentLinkedQueue removeIf() MethodThe removeIf() method of ConcurrentLinkedQueue class removes the elements of this queue that satisfies the given predicate filter. Syntax:Parameters:The parameter filter is a predicate which returns true for the elements to be removed. Specified By:The removeIf() method of ConcurrentLinkedQueue class is specified by: removeIf in interface Collection<E>. Return Value:The removeIf () method returns a Boolean value 'true' if the collection has removed any element, else it returns 'false'. Throws:It throws NullPointerException if the specified filter is null. Example 1Test it NowOutput: Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Number less than 11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Example 2Test it NowOutput: People eligible to vote : Name = Reema Age = 18 Name = Kajol Age = 37 Name = Ravi Age = 47 Example 3Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] at java.util.Collection.removeIf(Collection.java:410) at com.javaTpoint.ConcurrentLinkedQueueRemoveIfExample3.main(ConcurrentLinkedQueueRemoveIfExample3.java:13)
Next TopicJava ConcurrentLinkedQueue
|