Aleksandr Shitov

Greenhorn
+ Follow
since Jul 02, 2018
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Aleksandr Shitov

Piet Souris wrote:Hmmm, I start to belive that Alex Shitov is right, after all. My above code does not work; I added a third Map, and the reducing reduced the complete value Collection of all Maps, no matter what key it was.
Does anyone know what I am doing wrong?

Output:

******** The combined listt of the entries************
a=[1, 2, 3]
a=[2, 3, 4]
b=[10]
a=[3, 4, 5]
******************************************************
****** the final map, incorrect ************
a=[1, 2, 3, 2, 3, 4, 10, 3, 4, 5]
b=[1, 2, 3, 2, 3, 4, 10, 3, 4, 5]



This is because ArrayList in Collectors.reducing(new ArrayList<>(), ...) is created only once and used for each grouped key as initial(zero-size) list. Fixed version of compressMap2(...):



Thanks for evaluation)
6 years ago

Stephan van Hulst wrote:Welcome to CodeRanch Alex!

You can probably simplify your collection step with a groupingBy(), rather than a toMap().



Won't be work unfortunately, because there is no appropriate mapper for groupingBy function to flat grouped lists to one.
6 years ago
What do you think about that?
6 years ago