Method references

It is 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 that 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> ...

Get Java Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.