September 2019
Intermediate to advanced
816 pages
18h 47m
English
MelonCollector can be used via the new keyword, as follows:
Map<Boolean, List<Melon>> melons2000 = melons.stream() .collect(new MelonCollector());
We will receive the following output:
{ false = [Crenshaw(1200 g),Hemi(1600 g),Gac(1200 g),Horned(1700 g)], true = [Gac(3000 g),Hemi(2600 g),Apollo(2600 g), Gac(3000 g),Hemi(2600 g)]}
We can also use it via parallelStream():
Map<Boolean, List<Melon>> melons2000 = melons.parallelStream() .collect(new MelonCollector());
If we use the combiner() method, then the output may look as follows:
{false = [], true = [Hemi(2600g)]} ForkJoinPool.commonPool - worker - 7...{false = [Horned(1700g)], true = []} ForkJoinPool.commonPool - worker - 15 {false = [Crenshaw(1200g)], true = [Gac(3000g)]} ...