Java LinkedTransferQueue poll() MethodThe poll() method of LinkedTransferQueue class retrieves and removes the head of the LinkedTransferQueue. The method returns null if this queue is empty. Syntax:Parameters:NA Specified By:The poll() method of LinkedTransferQueue class is specified by poll() method in interface Queue<E>. Return Value:The poll() method returns this queue's head, or null if this queue is empty. Example 1Test it NowOutput: Head of queue is : Jack Elements left in queue : [Marry, Hack] Example 2Test it NowOutput: Output Head of queue is : John Elements left in queue : [Harry, Peter, Kristen] Java LinkedTransferQueue poll(long timeout, TimeUnit unit) MethodThe poll(long timeout, TimeUnit unit) method of LinkedTransferQueue class retrieves the head of this queue. It waits till the specified time is essential for an element to be available, and also removes it. The method returns null if this queue is empty. Syntax:Parameters:timeout - this is the time to wait before giving up(in units of the unit) unit - this is the TimeUnit deciding how to represent the timeout parameter Specified By:The poll() method of LinkedTransferQueue class is specified by poll() method in interface Queue<E>. Return Value:The poll() method returns this queue's head, or null if this queue is empty or if the assigned waiting time passes before the element is available. Throws:InterruptedException ?This exception will throw if interrupted while waiting Example 3Test it NowOutput: Head of queue : 67 Elements in queue : [109, 76, 876] Example 4Test it NowOutput: Peter gets the highest wages of 12000 Marry gets the second highest wages of 4500 Next TopicJava LinkedTransferQueue |
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