Java Data Struc. Cheat Sheet — Queues
1 min readApr 1, 2020
In Java, we broadly categorize Queues into the following two types
- Bounded Queues (all queues in java.util.concurrent package)
- Unbounded Queues (all queues in java.util package)
Bounded Queues
Bounded Queues are queues which are bounded by capacity that means we need to provide the max size of the queue at the time of creation.
For example: ArrayBlockingQueue
ArrayBlockingQueue
is a bounded, blocking queue backed by an array
BlockingQueue queue = new ArrayBlockingQueue(1024);
queue.put("1");
Object object = queue.take();
Unbounded Queues
Unbounded Queues are queues which are NOT bounded by capacity that means we should not provide the size of the queue.
For example LinkedList
Priority Queues
Class PriorityQueue<E>
An unbounded priority queue based on a priority heap.
References
- https://docs.oracle.com/javase/7/docs/api/java/util/Queue.html
- Bounded Queues and Unbounded Queues : https://www.journaldev.com/13244/java-queue