PriorityQueue
implements Queue
, but is PriorityQueue
a FIFO data structure like Queue
?
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.
No, it is not. As per Javadoc
The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used
AND
The head of this queue is the least element with respect to the specified ordering
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With