ConcurrentLinkedDeque in Java


The ConcurrentLinkedDeque Class in Java implements a deque and used a concurrent linked list for help. This class implements the Collection interface as well as the AbstractCollection 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.*;
public class Demo {
   public static void main(String[] args) {
      ConcurrentLinkedDeque<String> clDeque = new ConcurrentLinkedDeque<String>();
      clDeque.add("James");
      clDeque.add("May");
      clDeque.add("John");
      clDeque.add("Sara");
      clDeque.add("Anne");
      System.out.println("The elements in ConcurrentLinkedDeque are: " + clDeque);
   }
}

The output of the above program is as follows −

Output

The elements in ConcurrentLinkedDeque are: [James, May, John, Sara, Anne]

Now let us understand the above program.

The ConcurrentLinkedDeque is created and then elements are added to the front of the Deque. Finally, the elements are displayed. A code snippet that demonstrates this is given as follows −

ConcurrentLinkedDeque<String> clDeque = new ConcurrentLinkedDeque<String>();
clDeque.add("James");
clDeque.add("May");
clDeque.add("John");
clDeque.add("Sara");
clDeque.add("Anne");
System.out.println("The elements in ConcurrentLinkedDeque are: " + clDeque);

Updated on: 30-Jul-2019

33 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements