← Quiz: Queue, Deque and PriorityQueue: all 10 questions
Quiz: Queue, Deque and PriorityQueue · Question 5 of 10
You print a PriorityQueue with System.out.println(pq). What do you see?
You print a PriorityQueue with System.out.println(pq). What do you see?
- A.The elements in fully sorted order
- B.The internal heap array, which has the smallest first but is not fully sorted
- C.The elements in insertion order
- D.Only the smallest element
Answer & explanation
Correct answer: The internal heap array, which has the smallest first but is not fully sorted
toString walks the backing array. Only repeated poll() returns elements in sorted order.
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 →