flatmap


To put it in simple words, a map is for transformation while flatMap is a combination of transformation and flattering. flatMap () = map () + Flattening. 1. Map Function The map () method with Stream API takes a function as an argument. It applies the function on every element and mapping it to a new element.



The only difference is that the mapping method in the case of flatMap () produces a stream of new values, whereas for map (), it produces a single value for each input element. Arrays.stream (), List.stream (), etc, are commonly used mapping method for flatMap ().