I'm new to Java 8 optionals and I'm wondering if there is a way to combine these two statements into one while retaining the optional?
public List<String> getEmployeeStreetNames(Employee employee){
List<Addresses> addresses = Optional.ofNullable(employee)
.map(Employee::getAddresses)
.orElse(new ArrayList<>());
return addresses.stream()
.map(Address::getStreetName)
.collect(Collectors.toList())
}
Any help is greatly appreciated.