LearnFrenzy
Sign in Take a free test

Data Structures in Java · Data Structures in Java MCQ · Question 12

Order of a for-each loop over PriorityQueue Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

In what order does a for-each loop visit the elements of a PriorityQueue?

  • A Ascending order
  • B Insertion order
  • C No particular order (the internal heap array order) Correct
  • D Descending order
Correct Answer: Option C

Only poll removes elements in priority order; the iterator walks the heap array.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links