• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PriorityQueue

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you greg.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic