LinkedTransferQueue remove() method in Java Last Updated : 14 Sep, 2018 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) R rupesh_rao Follow 0 Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-LinkedTransferQueue +2 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like