import java.util.*;
class Priority{
public static void main(String args[]){
PriorityQueue queue=new PriorityQueue();
queue.add(\"Amit\
PriorityQueue
doesn't store the elements in sorted order, but it allows you to get the elements from it in sorted order. It just makes sure that the the element at the head is the least element as per the ordering used for it.
So, if you store multiple numbers - 2, 1, 4, 3, 6, 8
, it will make sure that 1
is the next element you remove. Then when you remove 1
, it moves 2
to head. It doesn't bother about the ordering of rest of the elements.