Java ArrayBlockingQueue removeIf() Method

The removeIf() method of Java ArrayBlockingQueue class removes the elements of the ArrayBlockingQueue 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 ArrayBlockingQueue class is specified by:

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

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

Output:

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

Example 3

Output:

Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Exception in thread "main" java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:203)
	at java.util.Collection.removeIf(Collection.java:410)
	at com.javaTpoint.ArrayBlockingQueueRemoveIfExample3.main(ArrayBlockingQueueRemoveIfExample3.java:15)

If the specified Predicate filter is null, it will give you NullPointerException as described in the above example.