I'm having employee objects and i want the sorted list by name in descending order and salary in ascending order.
class Employee {
String name;
Long salary;
}
I'm having employee objects and i want the sorted list by name in descending order and salary in ascending order.
class Employee {
String name;
Long salary;
}
To achieve what you are asking for, you may want to implement Comparable
interface in your class and then implement compareTo()
method in the way you want it to behave when you want objects of your class to be sorted.
Another possibility is to create your own Comparator, but first option seems to be easier one in this case.
Easy: compare by name and then, if the previous comparing returns 0, compare by salary.