🎙 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 4 of 10

What does this print? (code)

What does this print?

import java.util.*;
public class Main {
    public static void main(String[] args) {
        PriorityQueue<Integer> pq = new PriorityQueue<>(List.of(7, 3, 9, 1));
        pq.poll();
        System.out.println(pq.poll() + " " + pq.size());
    }
}
  1. A.1 3
  2. B.7 2
  3. C.9 2
  4. D.3 2
Answer & explanation

Correct answer: 3 2

The first poll removes 1 (the smallest). The second removes 3, leaving 2 elements.

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 →