🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Heaps & Priority Queues Quiz: all 8 questions

Heaps & Priority Queues Quiz · Question 5 of 8

In Java, how do you create a max-heap of integers?

In Java, how do you create a max-heap of integers?

  1. A.new PriorityQueue<>()
  2. B.new PriorityQueue<>(Collections.reverseOrder())
  3. C.new MaxHeap<>()
  4. D.new TreeSet<>()
Answer & explanation

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

PriorityQueue is a min-heap by default; reverseOrder() flips the comparison.

Can you get the rest right without peeking?

Take the timed Heaps & Priority Queues Quiz quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →