Java Programming Language: Queue Interface

Jesse L
2 min readSep 17, 2021

Hi everyone, welcome back. The queue is a data structure that adopts the FIFO or first-in-first-out technique meaning that the first item added is the first item that leaves or gets removed from the queue. The queue is a linear type of data structure and the java.util.queue interface provides methods that allow developers to interact with them. This is an informative article on the java.util.queue interface, for a more in depth tutorial using priorityQueues, click here.

Superinterfaces

The java.util.Queue interface extends from a couple other interfaces.

  • java.util.Collection
  • java.util.Iterable

Subinterfaces

The java.util.Queue interface is extended by other interfaces.

  • java.util.BlockingDeque
  • java.util.BlockingQueue
  • java.util.Deque
  • java.util.TransferQueue

Implementing Classes

Classes from java.util that implement the java.util.Queue interface:

  • AbstractQueue
  • ArrayBlockingQueue
  • ArrayDeque
  • ConcurrentLinkedDeque
  • ConcurrentLinkedQueue
  • DelayQueue
  • LinkedBlockedDeque
  • LinkedBlockedQueue
  • LinkedList
  • LinkedTransferQueue
  • PriorityBlockingQueue
  • PriorityQueue
  • SynchronousQueue

Inherited Methods

The Queue interface inherits methods from the java.util.Collection interface.

  • java.util.Collection: addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray

Queue Methods

Methods that are included within the java.util.Queue interface include:

  • add(E e): Adds in item at the back of the queue, returns true if successful.
  • element(): Views the first item at the front of the queue, returns the item at the front of the queue.
  • peek(): Views the first item at the front of the queue, returns the item at the front of the queue. peek() returns null if the queue is empty.
  • remove(): Removes the first item at the front of the queue and returns the item at the front of the queue.
  • poll(): Removes the first item at the front of the queue and returns the item at the front of the queue. poll() returns null if the queue is empty.
  • offer(E e): Adds an item to the back of the queue.

--

--

Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.