Java Program to Implement ConcurrentLinkedDeque API Last Updated : 19 Jan, 2021 Comments Improve Suggest changes Like Article Like Report ConcurrentLinkedDeque class in Java is an unbounded concurrent deque that stores its elements as linked nodes where each node contains the address of the previous as well as next nodes. It belongs to java.util.concurrent package. This class is a member of the Java Collections Framework. It also extends Object and AbstractCollection classes. Features of ConcurrentLinkedDeque API It does not allow null elements.Iterators are weakly consistent.Concurrent insertion, removal, and access operations execute safely across multiple threads so it is thread-safe.The size method is NOT a constant-time operation Implementing interfaces 1. Serializable 2. Iterable<E> 3. Collection<E> 4. Deque<E> 5. Queue<E> Parameters: E — The type of elements in the collection Syntax: public class ConcurrentLinkedDeque<E> extends AbstractCollection<E> implements Deque<E>, Serializable Constructors : public ConcurrentLinkedDeque(): It creates an empty deque.public ConcurrentLinkedDeque(Collection<E> c): It creates a deque that initially contains the elements of the Collection<E>. Methods: Method TypeDescriptionadd(E e) boolean Inserts an element in the tail of the dequeaddAll(Collection<E> c) boolean Inserts all the elements present in the specified CollectionaddFirst(E e) void Adds an element in the front of the dequeaddLast(E e) void Adds an element in the last of the dequeclear() voidRemoves all the elements from the dequecontains(Object o) boolean Returns true if the deque contains the Object OdescendingIterator() Iterator<E> Returns an iterator over the elements in the deque in reverse order. element() ERetrieves the head of the deque without removing itgetFirst() E Retrieves the first element of the dequegetLast() E Retrieves the last element of the dequeisEmpty() boolean Returns true if the deque contains no elements iterator() Iterator<E> Returns an iterator over the elements in the deque peek() E Retrieves the head of the deque without removing itpoll() E Retrieves and removes the head of the dequepush(E e) voidPushes an element onto the stack represented by the dequepop() EPops an element from the stack represented by the deque.remove() ERetrieves and removes the head of the queuesize() intReturns the size of the deque toArray() Object[]Returns an array containing all of the elements in the deque Implementation: Example Java // Java Program to Implement ConcurrentLinkedDeque API // Importing all classes from // java.util package import java.util.*; import java.util.concurrent.*; // Class class GFG { // Main driver method public static void main(String[] args) { // Object 1 // Create a ConcurrentLinkedDeque object // Declaring object of Integer type ConcurrentLinkedDeque<Integer> dq = new ConcurrentLinkedDeque<Integer>(); // Adding element to the front // using addFirst() method // Custom entry dq.add(89); // Adding an element in the last // using addLast() method // Custom entry dq.addLast(18); // Adding an element to the front // Custom inputs dq.addFirst(10); dq.add(45); // Displaying the current ConcurrentLinkedDeque System.out.println("ConcurrentLinkedDeque1 : " + dq); // Object 2 // Creating a ConcurrentLinkedDeque object // using ConcurrentLinkedDeque(Collection c) // Declaring object of Integer type ConcurrentLinkedDeque<Integer> ldq = new ConcurrentLinkedDeque<Integer>(dq); // Displaying the current ConcurrentLinkedDeque System.out.println("ConcurrentLinkedDeque2 : " + ldq); // Print the size of the deque // using size() method System.out.println("Size: " + ldq.size()); // Removing all the elements from the deque // using clear() method ldq.clear(); // Checking whether the ConcurrentLinkedDeque object // is empty or not System.out.println("Is Deque empty: " + ldq.isEmpty()); // Removing the head of deque of object1 dq.remove(); // Iterating over elements and // printing deque of object1 Iterator it = dq.iterator(); // Condition check using hasNext() which hold // true till single element remaining in List while (it.hasNext()) // Print all the elements System.out.print(it.next() + " "); } } OutputConcurrentLinkedDeque1: [10, 89, 18, 45] ConcurrentLinkedDeque2: [10, 89, 18, 45] Size: 4 Is Deque empty: true 89 18 45 Comment More infoAdvertise with us Next Article Java Program to Implement ConcurrentLinkedDeque API N namitachaudhary60 Follow Improve Article Tags : Java Java Programs Java-ConcurrentLinkedDeque Java-concurrent-package Practice Tags : Java Similar Reads Java Program to Implement ConcurrentLinkedQueue API The ConcurrentLinkedQueue class in Java is a part of the Java Collection Framework. It belongs to java.util.concurrent package. It was introduced in JDK 1.5. It is used to implement Queue with the help of LinkedList concurrently. It is an unbounded thread-safe implementation of Queue which inserts e 4 min read Java Program to Implement ConcurrentSkipListMap API ConcurrentSkipListMap API is based on the implementation of the ConcurrentNavigableMap. This map is sorted according to the natural ordering of its keys or by a Comparator provided on the map during creation time. This class implements a concurrent variant of SkipLists which makes its expected avera 10 min read Java Program to Implement ConcurrentHashMap API ConcurrentHashMap class obeys the same functional specification as HashTable and includes all the versions of methods corresponding to each method of a HashTable. A HashTable supports the full concurrency of retrievals and adjustable concurrency for updates. All the operations of ConcurrentHashMap a 6 min read Java Program to Implement ArrayBlockingQueue API ArrayBlockingQueue class is a member of the Java Collection framework. ArrayBlockingQueue is a bounded blocking queue. The term bounded, means that the size of the Queue is fixed and cannot be changed. Any attempt to put element/elements into a full queue will lead to blocking operation. Similarly, 7 min read Java Program to Implement DelayQueue API The DelayQueue class belongs to java.util.concurrent package. DelayQueue implements the BlockingQueue interface. DelayQueue is a specialized Priority Queue that orders elements supported their delay time. It means that only those elements can be taken from the queue whose time has expired. DelayQueu 7 min read ConcurrentLinkedDeque Spliterator() method in Java with Examples The spliterator() method of ConcurrentLinkedDeque returns a Spliterator on the elements of ConcurrentLinkedDeque. The returned iterator is weakly consistent. Spliterator can be used with Streams in Java 8. Spliterator can traverse elements individually and in bulk too. Syntax: public Spliterator spl 2 min read Different Approaches to Concurrent Programming in Java This article shows how to perform concurrent programming using Java threading framework. Let's analyze concurrent programming first: Concurrent Programming: This means that tasks appear to run simultaneously, but under the hood, the system might really be switching back and forth between the tasks. 7 min read Java Program to Implement LinkedList API Linked List is a part of the Collection framework That is present in java.util package. This class is an implementation of the LinkedList data structure which is a linear data structure in which the elements are not stored in contiguous locations and every element is a separate object with a data pa 10 min read Java Program to Implement PriorityQueue API A PriorityQueue is a linear data structure in which the elements are ordered according to their natural ordering or by some custom comparator provided at the queue at construction time. In PriorityQueue, the front of the queue points to the least element, and the rear points to the greatest element 4 min read Java Program to Implement SynchronousQueue API SynchronousQueue is a special blocking queue with no internal capacity. It helps in exchange data or information between threads in a thread-safe manner. SynchronousQueue has only 2 supported operations: Both of these are blocking method which means when we want to add a piece of information or data 3 min read Like