wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Usage of Comparable for sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Usage of Comparable for sorting" Watch "Usage of Comparable for sorting" New topic

Usage of Comparable for sorting

Sekhar Choudary
Ranch Hand

Joined: May 03, 2008
Posts: 57
can we use Comparable interface for sorting while using Arrays.sort() method
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
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.

SCJP 5 (98%) - SCBCD 5 (98%)
I agree. Here's the link: http://aspose.com/file-tools
subject: Usage of Comparable for sorting
It's not a secret anymore!