Home » Java ConcurrentLinkedQueue removeIf() Method

Java ConcurrentLinkedQueue removeIf() Method

by Online Tutorials Library

Java ConcurrentLinkedQueue removeIf() Method

The 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 1

Test it Now

Output:

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 2

Test it Now

Output:

People eligible to vote :   Name = Reema  Age = 18  Name = Kajol  Age = 37  Name = Ravi  Age = 47  

Example 3

Test it Now

Output:

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.tutorAspire.ConcurrentLinkedQueueRemoveIfExample3.main(ConcurrentLinkedQueueRemoveIfExample3.java:13)  

You may also like