Saturday, February 21, 2026
HomeLanguagesJavaLinkedTransferQueue removeAll() method in Java with Examples

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 a parameter containing elements to be removed from this list.

Returns: This method returns true if this list changed as a result of the call.

Exceptions: NULL Pointer Exception if this list contains a null element.

Below program illustrates the removeAll() function of LinkedTransferQueue class :

Program 1:




// Java code to illustrate
// removeAll() 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<String> LTQ
            = new LinkedTransferQueue<String>();
  
        // Add numbers to end of LinkedTransferQueue
        // using add() method
        LTQ.add("Lazyroar");
        LTQ.add("Geeks");
        LTQ.add("Computer Science");
        LTQ.add("Portal");
        LTQ.add("Gfg");
  
        // Print the Queue
        System.out.println("Linked Transfer Queue : "
                           + LTQ);
  
        // Get the ArrayList to be deleted
        ArrayList<String> arraylist
            = new ArrayList<String>();
        arraylist.add("Lazyroar");
        arraylist.add("Gfg");
        arraylist.add("hack");
  
        // Print ArrayList
        System.out.println("ArrayList to be deleted : "
                           + arraylist);
  
        // Removing elements from the queue
        // which are common to arraylist
        // using removeAll() method.
        LTQ.removeAll(arraylist);
  
        // Prints the Queue
        System.out.println("Linked Transfer Queue "
                           + "after removal of ArrayList : "
                           + LTQ);
    }
}


Output:

Linked Transfer Queue : [Lazyroar, Geeks, Computer Science, Portal, Gfg]
ArrayList to be deleted : [Lazyroar, Gfg, hack]
Linked Transfer Queue after removal of ArrayList : [Geeks, Computer Science, Portal]

Program 2:




// Java code to illustrate
// removeAll() 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(3);
        LTQ.add(6);
        LTQ.add(10);
        LTQ.add(125);
        LTQ.add(205);
  
        // print the Queue
        System.out.println("Linked Transfer Queue : "
                           + LTQ);
  
        // Get the ArrayList to be deleted
        ArrayList<Integer> arraylist
            = new ArrayList<Integer>();
        arraylist.add(10);
        arraylist.add(100);
        arraylist.add(125);
  
        // Print ArrayList
        System.out.println("ArrayList to be deleted : "
                           + arraylist);
  
        // Removing elements from the queue
        // which are common to arraylist
        // using removeAll() method.
        LTQ.removeAll(arraylist);
  
        // Prints the Queue
        System.out.println("Linked Transfer Queue "
                           + "after removal of ArrayList : "
                           + LTQ);
    }
}


Output:

Linked Transfer Queue : [3, 6, 10, 125, 205]
ArrayList to be deleted : [10, 100, 125]
Linked Transfer Queue after removal of ArrayList : [3, 6, 205]

Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/LinkedTransferQueue.html#removeAll-java.util.Collection-

RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS