LinkedTransferQueue remove() method in Java Last Updated : 14 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.util.concurrent.LinkedTransferQueue.remove() method is an in-built function in Java which is used to remove an element if it is present in this queue. Syntax: LinkedTransferQueue.remove(Object o) Parameters: The function accepts a single parameter o i.e. the object to be removed. Return Value: The function returns a true boolean value on successful removal of the object, otherwise returns false. Below programs illustrate LinkedTransferQueue.remove() method: Program 1: The element to be removed is present in the queue. Java // Java Program Demonstrate remove() // method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueRemoveExample1 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<Integer> queue = new LinkedTransferQueue<Integer>(); // Adding elements to this queue for (int i = 1; i <= 5; i++) queue.add(i); // Printing the elements of the queue System.out.println("The elements in the queue are:"); for (Integer i : queue) System.out.print(i + " "); // remove() method will remove the specified // element from the queue queue.remove(1); queue.remove(5); // Printing the elements of the queue System.out.println("\nRemaining elements in queue : "); for (Integer i : queue) System.out.print(i + " "); } } Output: The elements in the queue are: 1 2 3 4 5 Remaining elements in queue : 2 3 4 Program 2: The element to be removed is not present in the queue. Java // Java Program Demonstrate remove() // method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueRemoveExample2 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<Integer> queue = new LinkedTransferQueue<Integer>(); // Adding elements to this queue for (int i = 10; i <= 15; i++) queue.add(i); // Printing the elements of the queue System.out.println("The elements in the queue are:"); for (Integer i : queue) System.out.print(i + " "); // remove() method will remove the specified // element from the queue queue.remove(1); queue.remove(5); // Printing the elements of the queue System.out.println("\nRemaining elements in queue : "); for (Integer i : queue) System.out.print(i + " "); } } Output: The elements in the queue are: 10 11 12 13 14 15 Remaining elements in queue : 10 11 12 13 14 15 Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#remove(java.lang.Object) Comment More infoAdvertise with us Next Article LinkedBlockingQueue remove() method in Java R rupesh_rao Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-LinkedTransferQueue +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads LinkedTransferQueue offer() method in Java offer(E e, long timeout, TimeUnit unit) The offer(E e, long timeout, TimeUnit unit) method of java.util.concurrent.LinkedTransferQueue Class is an in-built function in Java which inserts the element passed as parameter to method at the tail of this queue, if queue is not full. It will wait till a sp 4 min read LinkedTransferQueue take() method in Java The java.util.concurrent.LinkedTransferQueue.take() method is an in-built function in Java which retrieves and remove the first element of the queue. This method also waits (if necessary) until an element becomes available. Syntax: LinkedTransferQueue.take() Parameters: The function does not accept 2 min read LinkedTransferQueue poll() method in Java The java.util.concurrent.LinkedTransferQueue.poll() method is an in-built function in Java which retrieves and remove the head of the queue if the queue is non-empty. Syntax: LinkedTransferQueue.poll() Parameters: The function does not accept any parameter. Return Value: The function returns the hea 2 min read LinkedTransferQueue removeIf() method in Java with Examples 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) Paramete 2 min read LinkedBlockingQueue remove() method in Java The remove(Object obj) method of LinkedBlockingQueue removes only one instance of the given Object, passed as parameter, from this LinkedBlockingQueue if it is present. It removes an element e such that obj.equals(e) and if this queue contains one or more instance of element e. This method returns t 4 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 Like