Stream operations flatMap
and map
accept a function as input.
flatMap
expects the function to return a new stream for each element of the stream and returns a stream which combines all the elements of the streams returned by the function for each element. In other words, with flatMap
, for each element from the source, multiple elements will be created by the function. http://www.zoftino.com/java-stream-examples#flatmap-operation
map
expects the function to return a transformed value and returns a new stream containing the transformed elements. In other words, with map
, for each element from the source, one transformed element will be created by the function.
http://www.zoftino.com/java-stream-examples#map-operation