Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Last active March 14, 2020 09:03
Show Gist options
  • Save ashkrit/c90dfbe0e27539326879cf30f5b41b65 to your computer and use it in GitHub Desktop.
Save ashkrit/c90dfbe0e27539326879cf30f5b41b65 to your computer and use it in GitHub Desktop.
//Address has priority , first home and then Office
Optional<String> address = Stream
.of(person.getHome().map(Home::getAddress), person.getOffice().map(Office::getAddress))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
address
.ifPresent(add -> System.out.println("Contacting at address " + add));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment