> Please note that, flatMap is not replacement for map.
> map() transformation, takes a function and applied that function to each element in the dataset and produce output for each element which is one-to-one of input element. One more difference is, map() output type need not be the same as input type.
> While flatMap() transformation produce an iterable output. Let’s take the example of WordCount example, in WordCount example we take one line and split the no. of words in a line so using flatMap() we can achieve the same (you can observe that you can iterate over the output i.e. (dataflair, 1), (technology,1) and so on) while the same is not possible with map().
> For more explanation, please go through map() and flatMap() example given by me in this forum.