LinkedTransferQueue put() method in Java Last Updated : 14 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The java.util.concurrent.LinkedTransferQueue.put() method is an in-built function in Java which is used to insert an element in this queue. It waits till the space becomes available if queue is full. Syntax: LinkedTransferQueue.put(E e) Parameters: The function accepts a single parameter e i.e. the element to be inserted. Return Value: The function does not return anything. Exception: The function shows NullPointerException when the specified element is Null. Below programs illustrate the LinkedTransferQueue.put() method: Program 1: Inserting Integers in the queue. Java /* Java Program Demonstrate put() method of LinkedTransferQueue */ import java.util.concurrent.*; class LinkedTransferQueuePutExample1 { 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.put(i); // Printing the elements of the queue System.out.println("The elements in the queue are:"); for (Integer i : queue) System.out.print(i + " "); } } Output: The elements in the queue are: 10 11 12 13 14 15 Program 2: Adding String in the queue. Java /* Java Program Demonstrate put() method of LinkedTransferQueue */ import java.util.concurrent.*; class LinkedTransferQueuePutExample2 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<String> queue = new LinkedTransferQueue<String>(); // Adding elements to this queue queue.put("alex"); queue.put("bob"); queue.put("chuck"); queue.put("drake"); queue.put("erick"); // Printing the elements of the queue System.out.println("The elements in the queue are:"); for (String i : queue) System.out.print(i + " "); } } Output: The elements in the queue are: alex bob chuck drake erick Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#put(E) Comment More infoAdvertise with us Next Article LinkedTransferQueue put() method in Java 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 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 peek() method in Java The java.util.concurrent.LinkedTransferQueue.peek() method is an in-built function in Java which is used to return the head of the queue if the queue is non-empty. Syntax: LinkedTransferQueue.peek() Parameters: The function does not accept any parameter. Return Value: The function returns the head o 2 min read LinkedTransferQueue size() method in Java The java.util.concurrent.LinkedTransferQueue.size() method is an in-built function in Java which gives the total count of the elements present in the queue. Syntax: LinkedTransferQueue.size() Parameters: The function does not accept any parameter. Return Value: The function returns the number of ele 2 min read 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 add() method in Java The add() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to insert an element in this queue. Syntax: LinkedTransferQueue.add(E e) Parameters: The function accepts a single parameter e i.e. the element to be inserted. Return Value: The function return 2 min read LinkedTransferQueue remove() method in Java 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 Val 2 min read LinkedTransferQueue drainTo() method in Java drainTo(Collection c) The drainTo(Collection c) method of java.util.concurrent.LinkedTransferQueue Class is an in-built function in Java which removes all the elements present in this queue and adds them to the provided collection. This is a more efficient way than repeatedly polling this queue. The 5 min read LinkedTransferQueue isEmpty() method in Java The isEmpty() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which checks if this queue is empty or not. Syntax: LinkedTransferQueue.isEmpty() Return Value: The function returns a boolean value. It returns true if the LinkedTransferQueue is empty and returns false 1 min read LinkedTransferQueue iterator() method in Java The iterator() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to return an iterator over the elements in this queue in proper sequence. Syntax: LinkedTransferQueue.iterator() Return Value: The function returns an iterator over the elements in this qu 2 min read Like