Java LinkedBlockingDeque poll() MethodThe poll() method of LinkedBlockingDeque class retrieves the head of the queue corresponding to this deque, and also removes it. This method returns null if this deque is empty. The poll(long timeout, TimeUnit unit) method of LinkedBlockingDequeclass retrieves the head of the queue corresponding to this deque, awaiting till the specified time is essential for an element to be available. Syntax:Parameters:
Specified By:The poll() method of LinkedBlockingDeque class is specified by:
Return Value:The poll() method returns this deque's head, and if this deque is empty returns null. The poll(long timeout,TimeUnit unit) method returns this deque's head, or null if the assigned waiting time passes before element is available. Throws:The poll() method throws InterruptedException if method is disrupted while waiting. Example 1Test it NowOutput: Deque before using poll() method : [Rahul, Sagar, Tarun, Vaibhav] Head of Deque is: Rahul Deque after using poll() method : [Sagar, Tarun, Vaibhav] Example 2Test it NowOutput: Deque before using poll() method : [15023001, 15023002, 15023003, 15023005, 15023007, 15023011] Head of Deque is: 15023001 Deque after using poll() method : [15023002, 15023003, 15023005, 15023007, 15023011] Example 3Test it NowOutput: First element of Deque is: Dwayne Deque after using poll() method : [Adam, Mark, Robret, Winston, Peter] Next TopicJava LinkedBlockingDeque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India