Skip to content
Advertisement

Is PriorityQueue a FIFO Queue?

PriorityQueue implements Queue, but is PriorityQueue a FIFO data structure like Queue?

Advertisement

Answer

From the Queue interface:

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied comparator, or the elements’ natural ordering

So PriorityQueue is an exception and it becomes a FIFO queue only if the comparator sorts in that order.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement