September 2019
Intermediate to advanced
816 pages
18h 47m
English
Now, let's combine the elements of this stream to express the following queries:
In order to calculate the total weight of melons, we need to sum up all the weights. For primitive specializations of Stream (IntStream, LongStream, and so on), the Java Stream API exposes a terminal operation named sum(). As its name suggests, this method sums up the elements of the stream:
int total = melons.stream() .mapToInt(Melon::getWeight) .sum();
After sum(), we also have the max() and min() terminal operations. Obviously, max() returns the maximum value of the stream, while ...