I have a class named Person
with multiple properties, for example:
public class Person {
private int id;
private String name, address;
// Many more properties.
}
A lot of Person
-objects are stored in an ArrayList<Person>
. I want to sort this list by multiple sort parameters, and different from time to time. For instance I might one time want to sort by name
ascending and then address
descending, and another time just by id
descending.
And I don't want to create my own sort methods (i.e., I want to use Collections.sort(personList, someComparator)
. What is the most elegant solution that achieves this?