Is it possible to sort employee objects first by their salary and if salaries of two objects are equal, then compare them by name using comparable and comparator interfaces?
For example, I have an Employee class as below
public class Employee{
private int salary;
private int name;
public Employee(salary,name){
this.salary = salary;
this.name = name;
}
//...........getter methods...........
}
Now suppose we have a list of Employee objects that have some salary amounts and names. I want to use comparator or comparable interface and sort the list in such a way that, list is sorted based on salaries and if salaries are same then in that case those two Employee objects have to be sorted by their names. Can someone please tell me if it is possible? A code snippet would be much appreciated.