Alternative sorting via Comparable, possible?
in
Programming Questions
•
1 years ago
Lets say i have a class: People. It has two fields, age and name. I'd like to some times sort by one some times by the other. The class implements Comparable. But i have to chose one field to use. I don't want to sort by one and than by the other, i'd like to be able to sort by one and/or the other. How can i do this?
this is it's compareTo:
I'm using rIn to compare. it's a string that represent time like 00:00:00:00 The paraSeg() converts them to seconds (int).
int compareTo(Object o)
{
Cortes other=(Cortes)o;
if(paraSeg(other.rIn)>paraSeg(rIn))
return -1;
if(paraSeg(other.rIn)==paraSeg(rIn))
return 0;
else
return 1;
}
1