Java LinkedBlockingDeque getFirst() method

21 Mar 2025 | 2 min read

The getFirst() method of LinkedBlockingDeque class returns the first element of this deque but does not withdraw it.

Syntax:

Parameters:

NA

Specified By:

The getFirst() method of LinkedBlockingDeque class is specified by getFirst() method in interface Deque<E>.

Return Value:

The getFirst() method returns the first element of this deque.

Throws:

The getFirst() method throws NoSuchElementException, if this deque is empty.

Example 1

Output:

 First element in the Queue is : 987 

Example 2

Output:

 Exception in thread "main" java.util.NoSuchElementException	at java.util.concurrent.LinkedBlockingDeque.getFirst(Unknown Source) 

Example 3

Output:

 Mansi got 41 bonus_points. Vaibhav got 33 bonus_points. Shraddha got 31 bonus_points. Vishal got 27 bonus_points. Shalu got 26 bonus_points. Abhi got 19 bonus_points. On the basis of bonus points, Promotion is awarded to : Mansi