Deques are double sided queues
Deques are double sided queues. Some block some do not. Some use CAS which works best with minimum contention. Others work best under high contention.
Some observations to take note off:
add methods throw IllegalStateException if they cannot add (because size limit has been reached)
offer methods also add elements by they return false if the element cannot be added. Note add methods throw exceptions if the element cannot be added.
remove methods throw NoSuchElementException if they cannot remove an element
poll methods return null if they cannot remove an element. Note that remove methods instead throw NoSuchElementException if they cannot remove an element.
get methods throw NoSuchElementException if they cannot get an element. Note they do not remove the element.
peek methods return null if they cannot get an element. They do not remove the element.
Here are the methods:
void addFirst(E e);
void addLast(E e);
boolean offerFirst(E e);
boolean offerLast(E e);
E removeFirst();
E removeLast();
E pollFirst();
E pollLast();
E getFirst();
E getLast();
E peekFirst();
E peekLast();
boolean add(E e);
boolean offer(E e);
E remove();
E poll();
E element();
E peek();
void push(E e);
E pop();
boolean remove(Object o);
Please see description of these in Queues:
LinkedList
ArrayDeque
LinkedBlockingDeque
ConcurrentLinkedDeque
Links
Back: Data Structures
Page Author: JD