LinkedBlockingDeque element() method in Java
The element() method of LinkedBlockingDeque returns the element at the front the container. It does not deletes the element in the container. This method returns the head of the queue represented by this deque.
Syntax:
public void element()
Parameters: This method does not accepts any parameter.
Returns: This method returns the head of the queue represented by this deque.
Below programs illustrate element() method of LinkedBlockingDeque:
Program 1:
// Java Program Demonstrate element() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(10); LBD.add(20); LBD.add(30); LBD.add(40); // before removing print queue System.out.println("Linked Blocking Deque: " + LBD); System.out.println("Linked Blocking Deque front element: " + LBD.element()); } } |
Linked Blocking Deque: [10, 20, 30, 40] Linked Blocking Deque front element: 10
Program 2:
// Java Program Demonstrate contains() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD = new LinkedBlockingDeque<String>(); // Add numbers to end of LinkedBlockingDeque LBD.add("ab"); LBD.add("cd"); LBD.add("fg"); LBD.add("xz"); // before removing print queue System.out.println("Linked Blocking Deque: " + LBD); System.out.println("Linked Blocking Deque front element: " + LBD.element()); } } |
Linked Blocking Deque: [ab, cd, fg, xz] Linked Blocking Deque front element: ab
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingDeque.html#element()
Recommended Posts:
- LinkedBlockingDeque put() method in Java
- LinkedBlockingDeque take() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque spliterator() method in Java
- LinkedBlockingDeque size() method in Java
- LinkedBlockingDeque addFirst() method in Java
- LinkedBlockingDeque toArray() method in Java with Example
- LinkedBlockingDeque offer() method in Java
- LinkedBlockingDeque removeFirstOccurrence() method in Java
- LinkedBlockingDeque drainTo() method in Java with Example
- LinkedBlockingDeque peek() method in Java
- LinkedBlockingDeque offerLast() method in Java
- LinkedBlockingDeque iterator() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



