I'm sure you're right. My rough idea goes like this:
Apply .stream() to the Optional<String> and you'll get a Stream<String> with 0 or 1 entries. You can use filter() instead of your if-statement, that's what filter() is for, then you need some kind of map() to convert a String to an int if you have one, then you need to make the result into an Optional. Give it a try.
Andrzej, your intuition is correct. Optional has map() and filter() methods - both of these are designed to do nothing on an empty Optional. So you don't have to check isPresent() before calling these methods - they will do that for you, internally.
Converting to stream() is unnecessary since Optional already has the needed methods.
Onion rings are vegetable donuts. Taste this tiny ad: