flatMap

An operation that turns each element into a stream, or an Optional, and joins the results into one flat stream, removing a level of nesting.

In more detail

On a stream of lists, flatMap(List::stream) produces one stream of all the inner elements. On Optional, flatMap is used when the transformation itself returns an Optional, so you do not end up with an Optional inside an Optional.

Example

groups.stream().flatMap(List::stream)

Related terms

Taught in

References

Certification courses