Java - how to sort object in many ways: Arrays.sort(), Comparable<T>
问题 Let's say that I have an array with objects, where I have some employees (objects). They all have: int age , double salary . I want to sort this array so my class implements Comparable <Employee> . I've made a method: public int compareTo(Employee other) { return Double.compare(salary, other.salary); } And it's ok, sorting is working fine. But I'm sorting by double salary . Now I want to sort by int age so what now? I've made a method: public int compareAge(Employee other) { return Integer