Open In App

LinkedTransferQueue removeAll() method in Java with Examples

Last Updated : 08 Mar, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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
// 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);
    }
}
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: Java
// 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-

Next Article

Similar Reads