To return the value of an optional, or a default value if the optional has no value, you can use orElse(other).
public String longestName() {
Optional<String> longNameOpt = someList.stream().max(Comparator.comparingInt(String::length));
return longNameOpt.orElse("not present");
}
Note that I rewrote your code for finding the longest name: you can directly use max(comparator) with a comparator comparing the length of each String. One such comparator can be obtained by calling Comparator.comparingInt(keyExtractor) with the key extractor being the method reference String::length
.