jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 2956

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: PriorityQueue
It's not a secret anymore!