🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Queue, Deque and PriorityQueue: all 10 questions

Quiz: Queue, Deque and PriorityQueue · Question 6 of 10

How do you make a PriorityQueue that gives the LARGEST element first?

How do you make a PriorityQueue that gives the LARGEST element first?

  1. A.new PriorityQueue<>(Comparator.reverseOrder())
  2. B.new PriorityQueue<>(true)
  3. C.new PriorityQueue<>().reverse()
  4. D.Use a TreeSet instead; PriorityQueue cannot do it
Answer & explanation

Correct answer: new PriorityQueue<>(Comparator.reverseOrder())

Passing a reversed comparator turns the min-heap into a max-heap.

Can you get the rest right without peeking?

Take the timed Quiz: Queue, Deque and PriorityQueue quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →