--Comparator allows you to sort by a specific value of your own class object.
python
//List<Person>Sort the list foo by x field
Collections.sort(
foo,
new Comparator<Person>() {
@Override
public int compare(Person obj1, Person obj2){
return obj2.getX - obj1.getX;
}
}
);
--Comparator.comparing allows you to write neatly
python
foo.sort(Comparator.comparing(Person::getX));
Recommended Posts