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 head of the queue if the queue is non-empty, otherwise it returns null.
Below programs illustrate the LinkedTransferQueue.poll() method:
Program 1:
/* 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 + " "); } } |
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 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 + " "); } } |
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()
Recommended Posts:
- PriorityBlockingQueue poll() method in Java
- PriorityQueue poll() Method in Java
- LinkedBlockingDeque poll() method in Java
- ArrayBlockingQueue poll() Method in Java
- ConcurrentLinkedQueue poll() method in Java
- ConcurrentLinkedDeque poll() method in Java with Example
- LinkedBlockingQueue poll() method in Java
- ArrayDeque poll() Method in Java
- Queue poll() method in Java
- DelayQueue poll() method in Java with Examples
- LinkedTransferQueue contains() method in Java
- LinkedTransferQueue take() method in Java
- LinkedTransferQueue put() method in Java
- LinkedTransferQueue add() method in Java
- LinkedTransferQueue drainTo() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



