Even though both map() and flatMap() can be used to transform one object to another by applying a method on each element.
The main difference is that flatMap() can also flatten the Stream. For example, if you have a list of the list, then you can convert it to a big list by using flatMap() function.