Difference between Map() and flatMap() in Java

FeaturesMap()flatMap()
Stream ProcessingIt processes a stream of valuesIt processes a stream of stream of values
OperationIt only does mappingIt performs both mapping and flattening
Mapper FunctionIts mapper function produces a single value for each input valueIts mapper function produces multiple values for each input value
MappingIt is a One-To-One mappingIt is a One-To-Many mapping
Data TransformationFrom Stream<T> to Stream<R>From Stream<Stream<T>> to Stream<R>
Use CaseUse this method when the mapper function is producing a single value for each input valueUse this method when the mapper function is producing multiple values for each input value