Skip to content

Stack, Queue, Deque in Java

Row of colorful dominoes blurring into the distance

Sooner or later, Java developers have to deal with the abstract data type queue, deque, and stack. In the stack, queue and deque tutorials, you will find answers to the following questions:

  • How do the queue, deque, and stack data structures work in general?
  • How do they differ?
  • How do the Java interfaces and classes Stack, Queue and Deque differ?
  • Which queue, deque, and stack implementations are provided by the JDK?
  • Which of the numerous implementations are suitable for which purposes?
  • How to implement queues, deques and stacks yourself?

You can find all code examples in the “Java Collections Guide” GitHub repository.

Data structures: What are stacks, queues, and deques?

A stack is a list of elements in which elements are inserted (“stacked”) and removed on the same side (in representations classically at the top):

Stack vs. queue vs. deque: stack data structure
Stack data structure

For more details, see the main article about the stack data structure.

A queue is a list of elements where elements are inserted on one side and removed in the same order on the other side:

Stack vs. queue vs. deque: queue data structure
Queue data structure

You can learn everything about queues in the main article about the queue data structure.

A deque (Double-ended queue, pronounced “deck”) is a list of elements where the elements can be inserted and removed both on one side and on the other:

Queue vs. Deque: deque data structure
Deque data structure

For details, see the main article about the deque data structure.

How do Stack, Queue, and Deque Differ?

The differences between the respective data structures are explained in the following articles:

What Java Implementations Are Available, and Which Should You Use?

The usage recommendations are based on the characteristics of the JDK queue and deque implementations, which are described in more detail in the linked articles.

The following are my recommendations for general purpose use:

The following queues are for special purposes:

What should I cover next? The best way for me to find out is through your feedback: a review on my ProvenExpert profile shows me which topics matter to you – and motivates me to write more articles.

👉 Leave a review

Would you like to be notified when new articles are published? Then click here to sign up for the HappyCoders newsletter.

👉 Newsletter Sign-up

Want Even More Knowledge?

My blog features many articles on Java, software architecture, and performance — from foundational concepts to advanced patterns.

If you want to go deeper, check out my trainings: hands-on, easy to understand, and directly applicable to your day-to-day project work. Instead of theory, I teach principles that help you write code that is better, more maintainable, and more performant in the long run.

Explore the Java Trainings

Become a Better Java Developer

My free newsletter keeps you ahead. Modern Java: new versions & features, performance, and JVM insights – once a month.

Search