I was looking around for a method to sort a list of objects based on just one of its multiple fields (and i ended up just asking the question myself) but in my research, I came across this answer:
https://stackoverflow.com/a/1421537/1549672
I'm fairly new to java and this may be why, but I don't quite understand this last method:
public static Comparator<Person> getComparator(final PersonComparator... multipleOptions) {
return new Comparator<Person>() {
public int compare(Person o1, Person o2) {
for (PersonComparator option : multipleOptions) {
int result = option.compare(o1, o2);
if (result != 0) {
return result;
}
}
return 0;
}
};
}
could someone please explain how it works...and what exactly it does? Thanks!