Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using a Comparator in Collections  RSS feed

 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




I have a doubt in this code, where is the compare method called in the CompDemo class ??
The output is F E D C B A.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From lines 19 through 24. Since you have specified a comparator, the compare() method is called when you add each element to the TreeSet.

Read -> http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html#TreeSet(java.util.Comparator)
 
Campbell Ritchie
Marshal
Posts: 55705
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By compareTo() I presume you mean compare()?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for correcting that Campbell... i have edited my initial reply..
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!