Quick Answer
map() transforms each element with a function that returns a single value - Stream becomes Stream. flatMap() transforms each element with a function that returns a Stream, then flattens all those streams into one - useful for one-to-many transformations. Example: stream of sentences, flatMap to words: sentences.stream().flatMap(s -> Arrays.stream(s.split(" "))).
Answer
map transforms each element individually. flatMap flattens nested structures like lists inside streams. Useful for handling nested collections.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.