Map vs flatMap in spark


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.



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 :-


tanq divyesh. The blog is too good.