Java Reference
In-Depth Information
Factory
method
Returned type
Used to
total, and average.
Example
use:
IntSummaryStatistics
menuStatistics
=
menuStream.collect(summarizingInt(Dish::getCalories));
joining
String
Concatenate the strings resulting from the invocation
of the toString method on each item of the stream.
Example use: String shortMenu = menuStream.map(Dish::getName).collect(joining(", "));
maxBy
Optional<T>
An Optional wrapping the maximal element in this
stream according to the given comparator or
Optional.empty() if the stream is empty.
Example use: Optional<Dish> fattest = menuStream.collect(maxBy(comparingInt(Dish::getCalories)));
minBy
Optional<T>
An Optional wrapping the minimal element in this
stream according to the given comparator or
Optional.empty() if the stream is empty.
Example use: Optional<Dish> lightest = menuStream.collect(minBy(comparingInt(Dish::getCalories)));
reducing
The type produced by the
Reduce the stream to a single value starting from an
reduction operation
initial value used as accumulator and iteratively
combining it with each item of the stream using a
BinaryOperator.
Example use: int totalCalories = menuStream.collect(reducing(0, Dish::getCalories, Integer::sum));
collectingAndThen
The type returned by the
Wrap another collector and apply a transformation
transforming function
function to its result.
Example use: int howManyDishes = menuStream.collect(collectingAndThen(toList(), List::size));
groupingBy
Map<K, List<T>>
Group the items in the stream based on the value of
one of their properties and use those values as keys in
the resulting Map.
 
Search WWH ::




Custom Search