LinkedTransferQueue removeIf() method in Java with Examples
The removeIf() method of java.util.concurrent.LinkedTransferQueue is an in-built function is Java which is used to remove all of the elements of this queue that satisfies a given predicate filter which is passed as a parameter to the method.
public boolean removeIf(Predicate filter)
Parameters: This method takes a parameter filter which represents a predicate which defines the filtering criteria for elements to be removed.
Return Value: This method returns a boolean value depicting if some the specified element has been removed. It returns True if the predicate returns true and the elements have been removed.
Exceptions: This method throws NullPointerException if the specified filter is null.
Below program illustrates the removeIf() function of LinkedTransferQueue class :
Linked Transfer Queue initially: [6, 3, 5, 15, 20] Multiples of 3 removed. Current Linked Transfer Queue: [5, 20]
Program 2: To demonstrate NullPointerException
Linked Transfer Queue initially: [6, 3, 5, 15, 20] Trying to remove null. java.lang.NullPointerException
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.