LinkedTransferQueue transfer() method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The transfer() method of class LinkedTransferQueue is an inbuilt function in Java which is generally used to transfer an element to a thread which is waiting to receive it, if there is no thread waiting then it will wait till a thread comes to waiting state as soon as waiting thread arrives element will be transferred into it. Syntax: public void transfer(E e) Parameter: This method accepts a mandatory parameter e which is the element to be transferred to the thread which is in waiting state. Return value: This method returns nothing, hence the return type is void. . Exceptions: This method throws the following exceptions: NullPointerException: If a program attempts to use an object reference that has the NULL value. InterruptedException: If interrupted while a thread is waiting or sleeping . Below programs illustrate the LinkedTransferQueue.transfer() method in Java: Program 1: To illustrate LinkedTransferQueue.transfer() method in Java. Java // Java program to illustrate // LinkedTransferQueue.transfer() method import java.util.*; import java.util.concurrent.*; class GFG { public static void main(String args[]) { LinkedTransferQueue<String> g = new LinkedTransferQueue<String>(); new Thread(new Runnable() { public void run() { try { System.out.println("Transferring" + " an element"); // Transfer a String element // using transfer() method g.transfer("is a computer" + " science portal."); System.out.println("Element " + "transfer is complete"); } catch (InterruptedException e1) { System.out.println(e1); } catch (NullPointerException e2) { System.out.println(e2); } } }).start(); try { // Get the transferred element System.out.println("Geeks for Geeks " + g.take()); } catch (Exception e) { System.out.println(e); } } } Output: Transferring an element Geeks for Geeks is a computer science portal. Element transfer is complete Program 2: To illustrate NullPointerException Java // Java program to illustrate // LinkedTransferQueue.transfer() method import java.util.*; import java.util.concurrent.*; class GFG { public static void main(String args[]) { LinkedTransferQueue<String> g = new LinkedTransferQueue<String>(); new Thread(new Runnable() { public void run() { try { System.out.println("Transferring" + " an element"); // Transfer a null element // using transfer() method g.transfer(null); System.out.println("Element " + "transfer is complete"); } catch (Exception e) { System.out.println(e); System.exit(0); } } }).start(); try { // Get the transferred element System.out.println("Geeks for Geeks " + g.take()); } catch (Exception e) { System.out.println(e); } } } Output: Transferring an element java.lang.NullPointerException Comment More infoAdvertise with us Next Article LinkedTransferQueue retainAll() method in Java with Examples S suman_ptnl Follow Improve Article Tags : Java Java - util package Java-Functions Java-LinkedTransferQueue Practice Tags : Java Similar Reads LinkedTransferQueue tryTransfer() method in Java with Examples The tryTransfer() method of class LinkedTransferQueue is an inbuilt function in Java which is generally used to transfer an element to a thread which is waiting to receive it, if in case there is no thread waiting then it will terminate without adding element into the queue or you can also make it w 5 min read LinkedTransferQueue toArray() method in Java with Examples public Object[] toArray() The toArray() method of Java.util.concurrent.LinkedTransferQueue is an in-built function is Java which is used to form an array of the same elements as that of LinkedTransferQueue. Basically, it copies all the element to the new array from the LinkedTransferQueue. Syntax: p 3 min read LinkedTransferQueue toString() method in Java with Examples The toString() method of java.util.concurrent.LinkedTransferQueue is an in-built function is Java which is used to return the string representation of the collection. The String representation consists of the elements of the collection enclosed in "[]" and separated by ", ". The order of elements in 2 min read LinkedTransferQueue retainAll() method in Java with Examples The retainAll() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to retain all the elements in this queue which are common to both i.e. the specified collection and this queue. All other elements which are not common are removed from this queue. Syntax 3 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 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 Like