Possible Duplicate:
Sorting Java objects using multiple keys
I have an employee class. Based on the employee name I want to sort. If the employee names for two objects (i.e. two employees) are same then I want to sort it with respect to the employee age.
For sorting w.r.t the employee name, I implemented the COmparable interface and used this code:
@Override
public int compareTo(Employee o) {
return name.compareTo(o.getName());
}
This bit of code is working fine for me. But I am not able to understand how to incorporate the sorting based on age when the name of two employee are same?
Do i need to use the Comparator for this? I am not sure how to achieve this.
Please help