flatMap in Java Stream

We can combine several lists of values into a single list of values using flatMap(). It’s called flatMap() because it flattens the Stream.

For Example, let’s say we have the below lists of names:

list1 = [“Gyan”,”Satya”,”Ram”]

list2 = [“Rohit”,”Jitu”]

list3 = [“Atul”,”Ajay”,”Praveen”,”Raj”]

After using flatMap(), we will end up with the below single list:

list = [“Gyan”,”Satya”,”Ram”,”Rohit”,”Jitu”,”Atul”,”Ajay”,”Praveen”,”Raj”]




Leave a Reply

Your email address will not be published. Required fields are marked *