LinkedBlockingDeque in Java


The LinkedBlockingDeque Class in Java has a blockingdeque that is optionally bounded and based on linked nodes. This class implements the Collection interface as well as the AbstractQueue class. It is a part of the Java Collection Framework.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.util.concurrent.LinkedBlockingDeque;
public class Demo {
   public static void main(String[] args) {
      LinkedBlockingDeque<String> lbDeque = new LinkedBlockingDeque<String>();
      lbDeque.add("James");
      lbDeque.add("May");
      lbDeque.add("John");
      lbDeque.add("Sara");
      lbDeque.add("Anne");
      System.out.println("Size of LinkedBlockingDeque is: " + lbDeque.size());
      System.out.println("The elements in LinkedBlockingDeque are: " + lbDeque);
   }
}

The output of the above program is as follows −

Output

Size of LinkedBlockingDeque is: 5
The elements in LinkedBlockingDeque are: [James, May, John, Sara, Anne]

Now let us understand the above program.

The LinkedBlockingDeque is created and then elements are added to it. Then the size of the LinkedBlockingDeque is displayed as well as its elements. A code snippet that demonstrates this is given as follows −

LinkedBlockingDeque<String> lbDeque = new LinkedBlockingDeque<String>();
lbDeque.add("James");
lbDeque.add("May");
lbDeque.add("John");
lbDeque.add("Sara");
lbDeque.add("Anne");
System.out.println("Size of LinkedBlockingDeque is: " + lbDeque.size());
System.out.println("The elements in LinkedBlockingDeque are: " + lbDeque);

Updated on: 30-Jul-2019

226 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements