Java 8 streams and lambdas

You might not be familiar with lambdas yet. In Java 8, every collection gets a default method stream(), which gives access to functional-style operations.

These operations can be either intermediate operations returning a stream, and thus allowing chaining, or a terminal operation that returns a value.

The most famous intermediate operations are as follows:

  • map: This applies a method to every element of a list and returns the list of results
  • filter: This returns a list of every element matching a predicate
  • reduce: This projects a list into a single value using an operation and an accumulator

Lambdas are shorthand syntax for function expressions. They can be coerced into a Single Abstract Method, an interface with only one ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.