0 votes
in JAVA by
Teeing Collectors JAVA12 Feature

1 Answer

0 votes
by

Teeing Collector is the new collector utility introduced in the Streams API.

This collector has three arguments – Two collectors and a Bi-function.

All input values are passed to each collector and the result is available in the Bi-function.

double mean = Stream.of(1, 2, 3, 4, 5)

                .collect(Collectors.teeing(

                        summingDouble(i -> i),

                        counting(),

                        (sum, n) -> sum / n));

System.out.println(mean);

The output is 3.0.

Related questions

0 votes
asked Jan 10, 2020 in JAVA by DavidAnderson
0 votes
asked Apr 21, 2020 in JAVA by Hodge
...