Java LinkedTransferQueue poll() Method

The 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 1

Test it Now

Output:

Head of queue is : Jack
Elements left in queue : [Marry, Hack]

Example 2

Test it Now

Output:

Output 
Head of queue is : John
Elements left in queue : [Harry, Peter, Kristen]

Java LinkedTransferQueue poll(long timeout, TimeUnit unit) Method

The 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 3

Test it Now

Output:

Head of queue : 67
Elements in queue : [109, 76, 876]

Example 4

Test it Now

Output:

Peter gets the highest wages of 12000
Marry gets the second highest wages of 4500





Latest Courses