Showing posts with label Flat. Show all posts
Showing posts with label Flat. Show all posts

Sunday, July 14, 2024

Java Map Interface


Streams

  What is the flat map? how it is different from map?

  • Map is used for data transformation whereas flat map is used for data transformation and flattering, the data.
    • Map takes stream as input and output as another stream.
    • It’s mapper function produces single value for each input value. Hence it is called as one to one mapping.
    • It processes, a stream of values.
    • It does Only mapping.
    • Its mapper function produces a single value for each input value.
    • It is a one-to-one mapping
    • Data transformation from stream to stream.
    • Use this method when the function is producing a single value for each input value.
  • Flatmap is when map is added with flattening.
    • It produces stream of values
    • It performs mapping as well as flattening.
    • Its map a function produces multiple values for each input value.
    • It is one too many mapping.
    • Data is transferred from one stream of stream to single stream.
    • Use this method when the mapper function is producing multiple values for each input value.
    • Flat map also takes a stream of input value and gives an output stream.
    • Its map function produces multiple value for each input value. Hence it is called as one to many mapping.
    • It is used to convert us stream of stream data to single stream, for example, a list of list of strings to a single list of strings.