Map vs flatMap in spark


#1

Hi all,

can any one help me on this. when to use map and when to use flatmap. what is the diff between map and flatmap.

can anyone explain it with scenarios.

Thanks,
Raghu.


#2

The map function transforms each element of collection into one element of collection. While, flatMap function transforms one element to one or multiple elements. For example :-

for detailed explanation visit :- https://data-flair.training/blogs/apache-spark-map-vs-flatmap/


#3

tanq divyesh. The blog is too good.