The function you pass to stream.map
has to return one object. That means each object in the input stream results in exactly one object in the output stream.
The function you pass to stream.flatMap
returns a stream for each object. That means the function can return any number of objects for each input object (including none). The resulting streams are then concatenated to one output stream.