Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a Comparator in Collections

 
shivang sarawagi
Ranch Hand
Posts: 158
  • 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
Sheriff
Pie
Posts: 50240
79
  • 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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic