flatMap is similar to map. The difference is described by the javadoc as follows:
This method is similar to map(Function), but the provided mapper is one whose result is already an Optional, and if invoked, flatMap does not wrap it with an additional Optional.
In other words, when you chain a...