Concept

How can lambda expressions build a multi-field Comparator?

ComputerScienceOne / Java 8: Lambda Expressions

"With respect to Comparators, we can use the following syntax to build a more complex ordering.\n\nComparator<Student> c =\n\n(a, b) -> a.getLastName().compareTo(b.getLastName());\n\nc = c.thenComparing((a, b) ->\n\na.getFirstName().compareTo(b.getFirstName()));\n\nc = c.thenComparing((a, b) -> a.getGpa().compareTo(b.getGpa()));\n\n//pass the comparator to the sort method:\n\nroster.sort(c);"

Related Ideas

How can lambda expressions build a multi-field Comparator? | ComputerScienceOne | Bifalgorithm | Bifalgorithm