Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- availableCountries.stream()
- .filter(country -> availableCountries.contains(country))
- // Stream<Country> of qualified countries
- .map(country -> Optional
- .ofNullable(availableDomains)
- // using availableDomains
- .orElse(Collections.emptyList())
- // or else an empty list (then the Collectors.toList() returns empty List as well)
- .stream()
- .filter(availableDomain -> availableDomain.getName().equals(country.getCountry()))
- // filter according to their names
- .findAny()
- .orElse(null))
- // or else is null
- .filter(Objects::nonNull)
- // filter the nulls out
- .collect(Collectors.toList());
- // and produce a List
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement