July 2023
Intermediate to advanced
276 pages
6h 55m
English
As programmers get introduced to the functional style of programming, they quickly learn about and get comfortable using the filter and map methods of the Stream API. Whenever we want to transform a collection of data into another collection, we quickly reach for the map method. That’s good, but we have to truly understand when this function is the right choice and when we may have to go beyond.
Let’s take a look at the code to get a list of first names from a list of persons.
| | List<String> firstNames = SAMPLE_DATA.stream() |
| | .map(Person::firstName) |
| | .toList(); |
| | |
| | System.out.println(firstNames); |
That’s simple code and it produces the desired result:
| | [John, Sara, Mike, Dev, Sara, Nancy, Jill] |
We got the first names ...
Read now
Unlock full access