beginnerFunctional Programming
What does the Stream filter() method do, and how is it different from map()?
filter() takes a Predicate and returns a new stream containing only the elements that satisfy it — it never changes the number of elements' TYPE, only how many pass through. map() takes a Function and transforms every element into something else, keeping the same count but potentially changing the type — the two are commonly chained, e.g. filter then map to select and transform in one pipeline.
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