Fundamentals 29 min read

Comprehensive Guide to the Java Queue Family – 18 Types, Interfaces, Implementations and Usage

This article provides an in‑depth overview of Java's Queue hierarchy, covering 18 concrete queue classes, their inheritance relationships, core methods, blocking behavior, real‑world analogies, and code examples, making it the most detailed reference on Java queues available today.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Comprehensive Guide to the Java Queue Family – 18 Types, Interfaces, Implementations and Usage

In the previous article "21 Pictures Explaining Collection Thread‑Safety" I left a hidden topic: Queue . This article focuses on the Queue family in Java, covering a total of 18 queue types, and is probably the most complete and detailed explanation on the market.

1. Queue Introduction

Hi, everyone, my English name is Queue , Chinese name is 队列 . In both real life and computers I play an important role.

I am a data structure that can be imagined as an array where elements enter from one end and leave from the other, following the FIFO (first‑in‑first‑out) principle.

I have two close siblings: List (list) and Set (set). They are all children of Collection . I also have a distant relative: Map . All belong to the java.util package.

1.1 Real‑world Scenarios

Restaurant waiting list (first‑come‑first‑served)

Mailboxes for letters

1.2 Computer‑world Scenarios

Message queues such as RabbitMQ

UDP protocol buffers

2. High‑Level Overview

18 queue types are divided into three major categories: interfaces, abstract classes, and concrete classes. Understanding the inheritance diagram helps a lot when studying the concrete implementations.

2.1 Interface Relationships

Queue extends Collection , which extends Iterable

BlockingQueue and Deque extend Queue

AbstractQueue implements Queue

Various other interfaces extend the above as shown in the diagram

3. The Core Queue Interface

3.1 Essence of Queue

Queue is a Collection designed for temporary storage of elements.

Provides extra insertion, removal and inspection operations, each with two variants: one throws an exception on failure, the other returns a special value (null or false).

Usually FIFO, but not mandatory; priority queues can order elements differently.

Each Queue must define its ordering semantics.

3.2 Core Methods

There are three groups of methods, each with two forms:

Action

Throws Exception

Returns Special Value

Insert

add(e)

offer(e)

Remove

remove()

poll()

Examine

element()

peek()

Examples:

Insertion: add(e) throws IllegalStateException when the queue is full; offer(e) returns false.

Removal: remove() throws NoSuchElementException when empty; poll() returns null.

Inspection: element() throws when empty; peek() returns null.

4. Deque – Double‑Ended Queue

4.1 Principles

Deque supports insertion and removal at both ends. The name deque is short for double‑ended queue.

4.2 Methods

Deque provides methods analogous to Queue (addFirst, addLast, pollFirst, pollLast, etc.) and can also act as a stack.

4.3 Implementations

LinkedList

ArrayDeque

ConcurrentLinkedDeque

LinkedBlockingDeque

5. AbstractQueue

AbstractQueue is an abstract class that implements most of the Queue operations by delegating to offer , poll and peek . Example implementations of add , remove and element are shown below.

public boolean add(E e) {
    if (offer(e))
        return true;
    else
        throw new IllegalStateException("Queue full");
}
public E remove() {
    E x = poll();
    if (x != null)
        return x;
    else
        throw new NoSuchElementException();
}
public E element() {
    E x = peek();
    if (x != null)
        return x;
    else
        throw new NoSuchElementException();
}

6. BlockingQueue

6.1 Overview

BlockingQueue adds blocking insertion and removal methods. When the queue is full, put blocks; when empty, take blocks.

6.2 Core Methods (10)

Four insertion methods (add, offer, put, timed‑offer), four removal methods (remove, poll, take, timed‑poll) and two inspection methods (element, peek).

6.3 Implementations

ArrayBlockingQueue

LinkedBlockingQueue

LinkedBlockingDeque

LinkedTransferQueue

SynchronousQueue

DelayQueue

PriorityBlockingQueue

7. BlockingDeque

Combines BlockingQueue and Deque. Provides all deque operations with blocking behavior.

8. TransferQueue

TransferQueue guarantees that an element is handed off to a consumer; if no consumer is waiting, the producer blocks until one arrives (or times out).

9. PriorityQueue

Supports natural ordering (ascending) or custom ordering via a Comparator . It is an unbounded, non‑blocking priority queue.

10. LinkedList

Implements List and Deque . Provides a doubly‑linked list structure, suitable for frequent insertions/removals at any position.

11. ConcurrentLinkedQueue

A thread‑safe, lock‑free, unbounded FIFO queue based on a linked‑node structure. Does not allow null elements.

12. ArrayDeque

Array‑based, resizable, non‑blocking deque. Not thread‑safe, does not permit nulls.

13. ConcurrentLinkedDeque

Thread‑safe, lock‑free, unbounded deque based on a linked structure.

14. ArrayBlockingQueue

Bounded, array‑backed blocking queue with optional fairness policy.

15. LinkedBlockingQueue

Linked‑node based blocking queue; optionally bounded, high throughput, used by many thread‑pool implementations.

16. LinkedBlockingDeque

Bounded or unbounded blocking deque; useful for work‑stealing algorithms.

17. LinkedTransferQueue

Combines the features of TransferQueue and a linked, unbounded queue.

18. SynchronousQueue

A hand‑off queue with no internal capacity; each put must wait for a matching take . Ideal for high‑throughput thread‑pool hand‑off.

19. PriorityBlockingQueue

Blocking version of PriorityQueue ; elements are ordered according to their natural ordering or a supplied comparator.

20. DelayQueue

Elements must implement Delayed . An element can only be taken when its delay has expired, making it suitable for scheduling and cache expiration.

This article spent a lot of effort on official documentation, diagrams, demo code and layout, and is probably the most complete and detailed explanation of Java queues available today.

JavaconcurrencyDataStructureQueueBlockingQueue
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.