Queue. Queue. Operations. Operations. public interface Queue<E> extends public interface Queue<E> extends Collection<E> Collection<E> { { E element(); E element(); boolean offer(E e); boolean offer(E e); E peek(); E peek(); E poll(); E poll(); E remove(); } E remove(); } Two forms of operations Two forms of operations Throws Throws exception exception Returns special Returns special value value Insert Insert add(e) add(e) offer(e) offer(e) Remove Remove remove() remove() poll() poll() Examine Examine element() element() peek() peek() Bounded queues Bounded queues java.util.concurrent java.util.concurrent java.util java.util Ordering of a queue Ordering of a queue Depending the ordering policy. (in natural Depending the ordering policy. (in natural ordering or comparator ordering policy) ordering or comparator ordering policy) Add() vs Offer() Add() vs Offer() IllegalStateException vs false IllegalStateException vs false Remove() vs poll() Remove() vs poll() Differ only when the queue is empty Differ only when the queue is empty NoSuchElementException vs null NoSuchElementException vs null Element() vs peek() Element() vs peek() NoSuchElementException vs null NoSuchElementException vs null Implementations Implementations LinkedBlockingQueue LinkedBlockingQueue — an optionally bounded — an optionally bounded FIFO blocking queue backed by linked nodes FIFO blocking queue backed by linked nodes ArrayBlockingQueue ArrayBlockingQueue — a bounded FIFO — a bounded FIFO blocking queue backed by an array blocking queue backed by an array PriorityBlockingQueue — an unbounded PriorityBlockingQueue — an unbounded blocking priority queue backed by a heap blocking priority queue backed by a heap DelayQueue — a time-based scheduling queue DelayQueue — a time-based scheduling queue backed by a heap backed by a heap SynchronousQueue SynchronousQueue . unbounded blocking priority queue backed by a heap blocking priority queue backed by a heap DelayQueue — a time-based scheduling queue DelayQueue — a time-based scheduling queue backed by a heap. ArrayBlockingQueue ArrayBlockingQueue — a bounded FIFO — a bounded FIFO blocking queue backed by an array blocking queue backed by an array PriorityBlockingQueue — an unbounded PriorityBlockingQueue — an. Implementations Implementations LinkedBlockingQueue LinkedBlockingQueue — an optionally bounded — an optionally bounded FIFO blocking queue backed by linked nodes FIFO blocking queue backed by linked nodes ArrayBlockingQueue ArrayBlockingQueue