O'Reilly logo

Java 9 Programming By Example by Peter Verhas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Method references

Lucky that we have Map, which pairs order items with product information, so we can invoke get on Map:

.map(piMap::get)

The map method is again something that has the same name as something else in Java and should not be confused. While the Map class is a data structure, the map method in the Stream interface performs mapping of the stream elements. The argument of the method is a Function (recall that this is a functional interface we recently discussed). This function converts a value, T, which is available as the element of the original stream (Stream<T>) to a value, R, and the return value of the map method is Stream<R>. The map method converts Stream<T> to Stream<R> using the given Function<T,R>, calling it for each ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required