Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about the order in which a PriorityQueue's iterator visits elements is true?

  • A.No particular order; only the head is guaranteed to be the smallest element.
  • B.Ascending order.
  • C.Insertion order.
  • D.Descending order.

Answer: A

The queue is a heap, which orders only enough to know the head; the javadoc states the iterator is not guaranteed to traverse in any particular order. Elements come out in priority order through repeated poll, not by iterating or printing the queue.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.