LinkedTransferQueue removeIf() method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: 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 : Program 1: Java // Java code to illustrate // removeIf() method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedTransferQueue LinkedTransferQueue<Integer> LTQ = new LinkedTransferQueue<Integer>(); // Add numbers to end of LinkedTransferQueue // using add() method LTQ.add(6); LTQ.add(3); LTQ.add(5); LTQ.add(15); LTQ.add(20); // Print the LTQ System.out.println("Linked Transfer Queue initially: " + LTQ); // Remove all multiple of 3 // using removeIf() method if (LTQ.removeIf(n -> (n % 3 == 0))) System.out.println("Multiples of 3 removed."); else System.out.println("No element removed."); // Print the LTQ System.out.println("Current Linked Transfer Queue: " + LTQ); } } Output: Linked Transfer Queue initially: [6, 3, 5, 15, 20] Multiples of 3 removed. Current Linked Transfer Queue: [5, 20] Program 2: To demonstrate NullPointerException Java // Java code to illustrate // removeIf() method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedTransferQueue LinkedTransferQueue<Integer> LTQ = new LinkedTransferQueue<Integer>(); // Add numbers to end of LinkedTransferQueue // using add() method LTQ.add(6); LTQ.add(3); LTQ.add(5); LTQ.add(15); LTQ.add(20); // Print the LTQ System.out.println("Linked Transfer Queue initially: " + LTQ); try { // Remove all multiple of 3 // using removeIf() method System.out.println("Trying to remove null."); LTQ.removeIf(null); } catch (Exception e) { System.out.println(e); } } } Output: Linked Transfer Queue initially: [6, 3, 5, 15, 20] Trying to remove null. java.lang.NullPointerException Reference: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/LinkedTransferQueue.html#removeIf(java.util.function.Predicate) Comment More infoAdvertise with us Next Article LinkedTransferQueue removeAll() method in Java with Examples P ProgrammerAnvesh Follow Improve Article Tags : Java Java - util package Java-Functions Java-LinkedTransferQueue Practice Tags : Java Similar Reads LinkedTransferQueue removeAll() method in Java with Examples The removeAll() method of java.util.concurrent.LinkedTransferQueue is an in-built function is Java which is used to remove from this queue all of its elements that are contained in the specified collection. Syntax: public boolean removeAll(Collection c) Parameters: This method takes collection c as 3 min read LinkedTransferQueue removeAll() method in Java with Examples The removeAll() method of java.util.concurrent.LinkedTransferQueue is an in-built function is Java which is used to remove from this queue all of its elements that are contained in the specified collection. Syntax: public boolean removeAll(Collection c) Parameters: This method takes collection c as 3 min read LinkedTransferQueue retainAll() method in Java with Examples The retainAll() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to retain all the elements in this queue which are common to both i.e. the specified collection and this queue. All other elements which are not common are removed from this queue. Syntax 3 min read LinkedTransferQueue retainAll() method in Java with Examples The retainAll() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to retain all the elements in this queue which are common to both i.e. the specified collection and this queue. All other elements which are not common are removed from this queue. Syntax 3 min read LinkedBlockingDeque removeIf() method in Java with Examples The removeIf() method of LinkedBlockingDeque removes the element from this LinkedBlockingDeque that satisfies the specified condition. Syntax: public boolean removeIf (Predicate<? super E> filter) Parameters: This method accepts a mandatory parameter filter which is the predicate value based o 2 min read LinkedBlockingDeque removeIf() method in Java with Examples The removeIf() method of LinkedBlockingDeque removes the element from this LinkedBlockingDeque that satisfies the specified condition. Syntax: public boolean removeIf (Predicate<? super E> filter) Parameters: This method accepts a mandatory parameter filter which is the predicate value based o 2 min read Like