Lambda expressions are a new and important feature included in Java SE 8. They provide a clear and concise way to represent one method interface using an expression. Lambda expressions also improve the
Collection libraries making it easier to iterate through, filter, and extract data from a
Collection. In addition, new concurrency features improve performance in multicore environments.
This Oracle by Example (OBE) provides an introduction to lambda expressions included in Java SE 8. An introduction to anonymous inner functions is provided, followed by a discussions of functional interfaces and the new lambda syntax. Then, examples of common usage patterns before and after lambda expressions are shown.
The next section reviews a common search use case and how Java code can be improved with the inclusion of lambda expressions. In addition, some of the common functional interfaces,
Function, provided in
java.util.function are shown in action.
The OBE finishes up with a review of how the Java collection has been updated with lambda expressions.