DEV Community

Discussion on: What is `map` in a Java Stream

Collapse
 
mbtts profile image
mbtts

Good article and thank you for sharing.

For those not aware it is also possible to use a method reference for the first example:

fruitList.stream()
         .map(Fruit::getName)
         .collect(toList());

This is just a more succinct syntax for invoking the #getName method on each and every instance of Fruit in the stream. As such even though it may appear to be invoked on the class it is not a static method.

Also a small API thing - it is Collectors#toList not #asList (and #toSet).