This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes PriorityQueue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PriorityQueue" Watch "PriorityQueue" New topic
Author

PriorityQueue

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
Hi,

I'm wondering how PriorityQueue works with natural order of String. Does it use hashcode of String to determine the order?
anyone knows answer to this? please

thank you

sura

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2849
    
  11

No, not the hashcode. That wouldn't give the natural order of String, which is simply alphabetical, or really lexicographical. It uses the String.compareTo(String) method. You can give the PriorityQueue a different Comparator to use if you want, say, a case-insensitive sorting.
sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
thank you greg.
 
wood burning stoves
 
subject: PriorityQueue