The 30 second answer
map is one-to-one: each element becomes one new element. flatMap is one-to-many: each element becomes a stream, and those streams are flattened into one. A typical example is turning a stream of orders into a stream of all line items. Java 16 also added mapMulti as an imperative alternative.
map is one-to-one (Stream<T> → Stream<R>). flatMap maps each element to a stream and flattens (one-to-many), for example:
orders.stream().flatMap(o -> o.items().stream())Java 16 added mapMulti as an imperative alternative when allocating many tiny streams is costly.
Sources:
Sources (0)
See inline citations in the answer above.