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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PriorityQueue" Watch "PriorityQueue" New topic


sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77

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


Greg Charles

Joined: Oct 01, 2001
Posts: 2841

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.
It is sorta covered in the JavaRanch Style Guide.
subject: PriorityQueue
Similar Threads
urgent please
Doubt in add() and offer() method of PriorityQueue
Priority Queue Ordering
TreeXxx VS PriorityQueue
Regarding java.lang.Comparator