The remove(Object o) method of ConcurrentLinkedQueue is used to remove a single instance of the specified element from this ConcurrentLinkedQueue, if it is present. This method removes an element e such that o.equals(e) if this ConcurrentLinkedQueue contains one or more such elements. Remove() method returns true if this ConcurrentLinkedQueue contained the specified element else it will return false. Syntax:
public boolean remove(Object o)
Parameter: This method takes a parameter o which represent element to be removed from this ConcurrentLinkedQueue. Returns: This method returns true if this ConcurrentLinkedQueue contained the specified element and removed. Below programs illustrate remove() method of ConcurrentLinkedQueue: Example 1:Â
Java
// Java Program Demonstrate remove()// method of ConcurrentLinkedQueueÂ
import java.util.concurrent.*;Â
public class GFG {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â
        // create an ConcurrentLinkedQueue        ConcurrentLinkedQueue<Integer>            queue = new ConcurrentLinkedQueue<Integer>();Â
        // Add Numbers to queue        queue.add(4353);        queue.add(7824);        queue.add(78249);        queue.add(8724);Â
        // Displaying the existing ConcurrentLinkedQueue        System.out.println("ConcurrentLinkedQueue: " + queue);Â
        // apply remove() for Number 78249        boolean response = queue.remove(78249);Â
        // print results        System.out.println("Removing Number 78249 successful: " + response);Â
        // Displaying the existing ConcurrentLinkedQueue        System.out.println("Updated ConcurrentLinkedQueue: " + queue);    }} |
ConcurrentLinkedQueue: [4353, 7824, 78249, 8724] Removing Number 78249 successful: true Updated ConcurrentLinkedQueue: [4353, 7824, 8724]
Example 2:Â
Java
// Java Program Demonstrate remove()// method of ConcurrentLinkedQueueÂ
import java.util.concurrent.*;Â
public class GFG {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â
        // create an ConcurrentLinkedQueue        ConcurrentLinkedQueue<String>            queue = new ConcurrentLinkedQueue<String>();Â
        // Add String to queue        queue.add("Aman");        queue.add("Amar");        queue.add("Sanjeet");        queue.add("Rabi");Â
        // Displaying the existing ConcurrentLinkedQueue        System.out.println("ConcurrentLinkedQueue: " + queue);Â
        // apply remove() on queue        boolean response1 = queue.remove("Aman");Â
        // print after applying remove method        System.out.println("Removing String \"Aman\" successful: " + response1);Â
        // Displaying the existing ConcurrentLinkedQueue        System.out.println("Updated ConcurrentLinkedQueue: " + queue);Â
        // apply remove() on queue        boolean response2 = queue.remove("Kisan");Â
        // print after applying remove method        System.out.println("Removing String \"Kisan\" successful: " + response2);Â
        // Displaying the existing ConcurrentLinkedQueue        System.out.println("Updated ConcurrentLinkedQueue: " + queue);    }} |
ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi] Removing String "Aman" successful: true Updated ConcurrentLinkedQueue: [Amar, Sanjeet, Rabi] Removing String "Kisan" successful: false Updated ConcurrentLinkedQueue: [Amar, Sanjeet, Rabi]
