Skip to content
Advertisement

Java use streams map to return desired JSON Structure

I’m new to Java I have an array like below

JavaScript

I have to format the same into below structure

JavaScript

Please help me how we can do this with Java streams

I have tried the below

JavaScript

But that’s not the expected result

Advertisement

Answer

Use groupingBy with downstream Collector:

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