Removing top of PriorityQueue?
问题 Assume that I am using the PriorityQueue class from Java.util. I want to remove the largest number from the PriorityQueue pq, which we assume is at the head of the queue. Will the following work? // 1 int head = pq.peek(); pq.dequeue(head); // 2 int head = pq.dequeue(pq.peek()); Would this work the same for non-primitives as well? 回答1: Queue#peek and Queue#element return the head value of the queue, Queue#poll and Queue#remove return and remove it. It looks like int head = pq.poll(); is what