I came across this example https://compiler.javatpoint.com/opr/test.jsp?filename=JavaPriorityQueueComparatorExample2 Here to my surprise priority queue is printing them in order of Ram got 98 marks. Rahul got 19 marks. Himanshu got 78 marks. Geetanjali got 18 marks.
Instead of Ram got 98 marks. Himanshu got 78 marks. Rahul got 19 marks. Geetanjali got 18 marks.
I ran this in eclipse and I noticed something interesting which I don't know why that is happening but when himanshu was getting added to the priority queue, it comparator checked it against Ram and not Rahul why? How I think a priority Queue works is that if a is greater than b then return -1 to show that b priority is lower than a. I would appreciate if someone could explain this.