← 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?
- A.new PriorityQueue<>(Comparator.reverseOrder())
- B.new PriorityQueue<>(true)
- C.new PriorityQueue<>().reverse()
- 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 →