This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Usage of Comparable for sorting

 
Sekhar Choudary
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we use Comparable interface for sorting while using Arrays.sort() method
 
Ralph Jaus
Ranch Hand
Posts: 342
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The comparable interface is used implicitely: If your class, say A, implements Comparable and you sort an array of type A[], its compareTo method is used for sorting.

Moreover, you can define a comparator class that implements the Comparator interface and use it explicitely in the sort method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic