Skip to content
Advertisement

Stream groupBy to nested maps with casting

Need to calculate total number by gender from below structure of nested Maps. But as data stored as Object need to cast it at every iteration. After grouping not able to cast last leaf Map to calculate and filter date object.

JavaScript

Applied below stream,

JavaScript

Advertisement

Answer

It is a rather unusual way to store data. I would recommend you to implement appropriate classes, such as person with the appropriate fields like gender, age, weight etc.

But if you want to stick with your data structure, something like below should work:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement