← 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());
}
}
- A.1 3
- B.7 2
- C.9 2
- 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 →