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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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("GeeksforGeeks");
        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("GeeksforGeeks");
        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);
    }
}

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


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-



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.