File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparator Interface

 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: K& B Master Exam


Here the answer is Good,Ugly,Bad. How is it sorted??? Can anyone explain the flow of the program.I am getting confused with the compare() method.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the answer is Good,Ugly,Bad. How is it sorted??? Can anyone explain the flow of the program.I am getting confused with the compare() method.


The purpose of the compare() method is to report the greater of two objects. With this method, an order can be established, and hence, the array can be sorted.

If you look at the compare method. It is reporting, the greater, based only on the second letter, and opposite of what the ASCII values are. Hence, the second letter is sorted in reverse order -- in this case, "o", "g", and "a".

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic