Skip to content
Related Articles

Related Articles

LinkedBlockingDeque element() method in Java
  • Last Updated : 19 Nov, 2020

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 accept 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




// 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());
    }
}
Output: 
Linked Blocking Deque: [10, 20, 30, 40]
Linked Blocking Deque front element: 10




 

Program 2: 

Java




// 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<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());
    }
}
Output: 
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()
 

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :