Concept
How can method references and Comparator methods make ordering more concise?
ComputerScienceOne / Java 8: Lambda Expressions
"We can make this even more terse using method references, another new feature in Java 8.\n\n//using getters as key extractors\n\nmyList.sort(\n\nComparator.comparing(Student::getLastName)\n\n.thenComparing(Student::getFirstName)\n\n.thenComparing(Student::getGpa));\n\nThere are several other convenient methods provided by the updated Comparator interface. For example, the reversed() member method returns a new Comparator that defines the reversed order. The static methods, nullsFirst() and nullsLast() can be used to modify a Comparator to order null values."
Related Ideas
- How can lambda expressions simplify sorting a list?ComputerScienceOne · Java 8: Lambda Expressions
- What PHP programming language topics are listed?ComputerScienceOne · Java 8: Lambda Expressions . . . . . . . . . . . . . . . . . . . . .
- How does Java sort arrays and lists with comparators?ComputerScienceOne · Sorted Collections
- How can anonymous classes define custom Java comparators?ComputerScienceOne · Comparators
- How can a Java Comparator handle null values?ComputerScienceOne · Importance of javaequals() and javahashCode() Methods