LinkedTransferQueue poll() method in Java Last Updated : 14 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 head of the queue if the queue is non-empty, otherwise it returns null. Below programs illustrate the LinkedTransferQueue.poll() method: Program 1: Java /* Java Program Demonstrate poll() method of LinkedTransferQueue */ import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueuePollExample1 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<Character> queue = new LinkedTransferQueue<Character>(); // Adding elements to this queue for (char ch = 'A'; ch <= 'Z'; ch++) { queue.add(ch); } // Printing the head of the queue System.out.println("The head of the queue is " + queue.poll()); // Printing remaining elements of the queue System.out.println("The elements in the queue :"); for (Character i : queue) System.out.print(i + " "); } } Output: The head of the queue is A The elements in the queue : B C D E F G H I J K L M N O P Q R S T U V W X Y Z Program 2: Java /* Java Program Demonstrate poll() method of LinkedTransferQueue */ import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueuePollExample2 { 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 <= 50; i += 10) queue.add(i); // Printing the head of the queue System.out.println("The head of the queue is " + queue.poll()); // Printing remaining elements of the queue System.out.println("The elements in the queue :"); for (Integer i : queue) System.out.print(i + " "); } } Output: The head of the queue is 10 The elements in the queue : 20 30 40 50 Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#poll() Comment More infoAdvertise with us Next Article LinkedTransferQueue put() 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 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 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 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 Like