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
1. Serializable 2. Iterable<E> 3. Collection<E> 4. Deque<E> 5. Queue<E>
Parameters: E — The type of elements in the collection
public class ConcurrentLinkedDeque<E> extends AbstractCollection<E> implements Deque<E>, Serializable
- 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>.
Method Type Description add(E e) boolean Inserts an element in the tail of the deque addAll(Collection<E> c) boolean Inserts all the elements present in the specified Collection addFirst(E e) void Adds an element in the front of the deque addLast(E e) void Adds an element in the last of the deque clear() void Removes all the elements from the deque contains(Object o) boolean Returns true if the deque contains the Object O descendingIterator() Iterator<E> Returns an iterator over the elements in the deque in reverse order. element() E Retrieves the head of the deque without removing it getFirst() E Retrieves the first element of the deque getLast() E Retrieves the last element of the deque isEmpty() 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 it poll() E Retrieves and removes the head of the deque push(E e) void Pushes an element onto the stack represented by the deque pop() E Pops an element from the stack represented by the deque. remove() E Retrieves and removes the head of the queue size() int Returns the size of the deque toArray() Object Returns an array containing all of the elements in the deque
ConcurrentLinkedDeque1: [10, 89, 18, 45] ConcurrentLinkedDeque2: [10, 89, 18, 45] Size: 4 Is Deque empty: true 89 18 45
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.