LinkedTransferQueue take() method in Java Last Updated : 14 Sep, 2018 Comments Improve Suggest changes Like Article Like Report 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 any parameter. Return Value: The function returns the first element of the queue. Exceptions: The function throws InterruptedException if interrupted while waiting. Below programs illustrate the java.util.concurrent.LinkedTransferQueue.take() : Program 1: Java // Java Program Demonstrate take() // method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueTakeExample1 { public static void main(String[] args) throws Exception { // Initializing the queue LinkedTransferQueue<String> queue = new LinkedTransferQueue<String>(); // Adding elements to this queue queue.add("Alex"); queue.add("Bob"); queue.add("Chuck"); queue.add("Drake"); queue.add("Eric"); // Printing the elements System.out.println("Elements are :"); for (String xyz : queue) { // will take and remove the head of the queue System.out.println(queue.take()); } // Printing the size of the Queue System.out.println("Queue Size: " + queue.size()); } } Output: Elements are : Alex Bob Chuck Drake Eric Queue Size: 0 Program 2: Java // Java Program Demonstrate take() // method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueTakeExample2 { public static void main(String[] args) throws Exception { // 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 System.out.println("Elements are :"); for (Integer xyz : queue) { // will take and remove the head of the queue System.out.println(queue.take()); } // Printing the size of the Queue System.out.println("Queue Size: " + queue.size()); } } Output: Elements are : 1 2 3 4 5 Queue Size: 0 Reference : https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#take() Comment More infoAdvertise with us Next Article LinkedTransferQueue take() 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 put() method in Java 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 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 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 Like