Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. availableCountries.stream()
  2. .filter(country -> availableCountries.contains(country))
  3. // Stream<Country> of qualified countries
  4. .map(country -> Optional
  5. .ofNullable(availableDomains)
  6. // using availableDomains
  7. .orElse(Collections.emptyList())
  8. // or else an empty list (then the Collectors.toList() returns empty List as well)
  9. .stream()
  10. .filter(availableDomain -> availableDomain.getName().equals(country.getCountry()))
  11. // filter according to their names
  12. .findAny()
  13. .orElse(null))
  14. // or else is null
  15. .filter(Objects::nonNull)
  16. // filter the nulls out
  17. .collect(Collectors.toList());
  18. // and produce a List
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement