Skip to content
Advertisement

Combine list of list into map using stream

I’m trying to convert a pojo object that looks like

JavaScript

into Map<String, List<String>>, such as:

JavaScript

how can I accomplish this using stream? I preferably want to utilize stream into collect(), instead of using forEach() (which is basically a for-loop).

Thanks in advance.

EDIT: The pojo class looks something like:

JavaScript

And I basically have List<Pojo>

Advertisement

Answer

You can do it using stream, create entry for each type and id combination and then do a group by

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