intermediateJava 8 & Streams82 of 436

Difference between map() and flatMap().

Tests whether you know map() transforms each element 1:1 (possibly producing a stream of streams), while flatMap() transforms and then flattens nested structures into a single stream -- the mechanism you need whenever each input maps to zero or more outputs.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

← Back to all Core Java questions