Chapter
Java 8: Lambda Expressions
From ComputerScienceOne by Dr Chris Bourke
Concepts
- How can lambda expressions simplify sorting a list?
"Java 8 introduced a lot of functional-style syntax, including lambda expressions. Lambda expressions are essentially anonymous functions that can be passed around to other methods or objects. One use
- How can lambda expressions build a multi-field Comparator?
"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.thenCompari
- How can method references and Comparator methods make ordering more concise?
"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.thenCom