You could do it like this:
Optional<String> resultOpt = Optional.of(find1()
.orElseGet(() -> find2()
.orElseGet(() -> find3()
.orElseThrow(() -> new WhatEverException()))));
Though I'm not sure it improves readability IMO. Guava provides a way to chain Optionals:
import com.google.common.base.Optional;
Optional<String> resultOpt = s.find1().or(s.find2()).or(s.find3());
It could be another alternative for your problem but does not use the standard Optional class in the JDK.
If you want to keep the standard API, you could write a simple utility method:
static <T> Optional<T> or(Optional<T> first, Optional<T> second) {
return first.isPresent() ? first : second;
}
and then:
Optional<String> resultOpt = or(s.find1(), or(s.find2(), s.find3()));
If you have a lot of optionals to chains, maybe it's better to use the Stream approach as other mentionned already.