This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes [SCJP] PriorityQueue order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "[SCJP] PriorityQueue order" Watch "[SCJP] PriorityQueue order" New topic

[SCJP] PriorityQueue order

Paulo Gervásio

Joined: Jun 12, 2010
Posts: 4
Hi, I have one doubt about how PriorityQueue prints yours items when calls toString() ...
Let me explain better, I have this code:

and it prints [1, 3, 2]...

Look what the JavaDoc says about Iterator:
Returns an iterator over the elements in this queue. The iterator does not return the elements in any particular order.

Anyone knows what is this order or in what its based?


Ps.: This code I found in
Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

This question has been asked many times before like here, here and here...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
subject: [SCJP] PriorityQueue order
Similar Threads
Doubt in PriorityQueue
Doubt on PriorityQueue?
another question from
Ordering in PriorityQueue