• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a Comparator in Collections

 
shivang sarawagi
Ranch Hand
Posts: 155
  • 0
  • 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
  • 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: 47293
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By compareTo() I presume you mean compare()?
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for correcting that Campbell... i have edited my initial reply..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic