Difference between map()
and flatMap()
:
The map()
operates on the individual elements of the stream and returns a value as a Stream with the results. The flatMap()
operates on the individual elements of the stream and returns a value as a Stream
with the results. In this they are similar.
However the map()
takes in a function that returns any R
(could be a Stream
as well) whereas the flatMap()
operation takes in a function that returns a Stream
.