5 AnswersNew Answer
meghanamadhub 1003 Hope this article will help you https://medium.com/omarelgabrys-blog/priority-queues-11e469cda253
A PriorityQueue is used when the objects are supposed to be processed based on the priority. It is known that a queue follows First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority, that’s when the PriorityQueue comes into play. The PriorityQueue is based on the priority heap. The elements of the priority queue are ordered according to the natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. this will help u to understood the concepts of priority queue https://www.google.com/amp/s/www.geeksforgeeks.org/priority-queue-class-in-java-2/amp/
A priority queue is an abstract data type similar to regular queue or stack data structure in which each element additionally has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. In some implementations, if two elements have the same priority, they are served according to the order in which they were enqueued, while in other implementations, ordering of elements with the same priority is undefined.
You obviously don't understand priority queues. A priority queue in Java is a special type of queue wherein all the elements are ordered as per their natural ordering or based on a custom comparator supplied at the time of creation. It's the custom comparator that's the thing to note here. See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PriorityQueue.html.
Do any anyone know more about this. If yes plz share