Skip to content

Instantly share code, notes, and snippets.

@rnaufal
Created March 6, 2018 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnaufal/2ea8b681d694debbed8e0aaef8edf14a to your computer and use it in GitHub Desktop.
Save rnaufal/2ea8b681d694debbed8e0aaef8edf14a to your computer and use it in GitHub Desktop.
Collection<Car> allPeopleCars = people
.stream()
.map(Person::getCars)
.flatMap(mayHaveCars -> mayHaveCars.map(Collection::stream).orElse(Stream.empty()))
.collect(Collectors.toList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment