Last Updated : 11 Jul, 2025
The java.util.concurrent.ConcurrentLinkedDeque.element() is an in-built function in java which retrieves but does not remove the head of the queue represented by deque i.e the first element of deque.
Syntax:
conn_linked_deque.element()
Parameter: This method has no parameters.
Return Value: This method returns the first element in the deque.
Exception: This method will throw NoSuchElementException if the deque is empty.
Below programs illustrate the ConcurrentLinkedDeque.element() method:
Program 1: This program involves a ConcurrentLinkedDeque of Integer type.
// Java example illustrating
// ConcurrentLinkedDeque element() method
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
// Create a ConcurrentLinkedDeque
// using ConcurrentLinkedDeque() constructor
ConcurrentLinkedDeque<Integer>
cld = new ConcurrentLinkedDeque<Integer>();
cld.add(12);
cld.add(70);
cld.add(1009);
cld.add(475);
// Displaying the existing LinkedDeque
System.out.println("ConcurrentLinkedDeque: "
+ cld);
// Displaying the head of deque
System.out.println("The Head of deque is: "
+ cld.element());
}
}
ConcurrentLinkedDeque: [12, 70, 1009, 475] The Head of deque is: 12
Program 2: This program involves a ConcurrentLinkedDeque of String type.
// Java example illustrating
// ConcurrentLinkedDeque element() method
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
// Create a ConcurrentLinkedDeque
// using ConcurrentLinkedDeque() constructor
ConcurrentLinkedDeque<String>
cld = new ConcurrentLinkedDeque<String>();
cld.add("Gfg");
cld.add("Geeks");
cld.add("Programming");
cld.add("contribute");
// Displaying the existing LinkedDeque
System.out.println("ConcurrentLinkedDeque: "
+ cld);
// Displaying the head of deque
System.out.println("The Head of deque is: "
+ cld.element());
}
}
ConcurrentLinkedDeque: [Gfg, Geeks, Programming, contribute] The Head of deque is: Gfg
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4