Save India From Corruption - Anna Hazare.
Save India From Corruption - Anna Hazare.
Ravi Kiran V wrote:Thanks Stephan ,
that was a valuable information .
You mean to say that we must use Comparable interface to sort in a natural order only ??
Thanks in advnace .
Steve
What he means is that the Comparable interface defines the natural order
Save India From Corruption - Anna Hazare.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Ravi Kiran V wrote:
Ravi Kiran V wrote:But when we implement the Comparable interface and override the compareTo method , cant we redefine the sorting order based on the return type of compareTo method ??
Steve
OCPJP 6-100%; Preparing for GATE11
Java Programmer | SCJP 1.5 | SCWCD 1.4
Save India From Corruption - Anna Hazare.
Stephan van Hulst wrote:I like how you can give a class a 'natural order' by making it a Comparable. This is the interface I use most. In this case a class has an inherent order.
However, what happens when you have a class that is already comparable, but you want to sort it in a different way than its natural order? Then you can still provide a separate Comparator object.
- Rohit
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|