Skip to content
Advertisement

How do i make use of groupingby in java

I have a movie list from a web service that i need to group using genres attribute from the data. My question is very similar to this groupby ngFor angular2 but in java instead.

movie list from the web service looks like this

JavaScript

here is what i’m trying to achieve but i cant seems to get it right

JavaScript

i’ve tried replicating the javascript solution from the answer in groupby ngFor angular2 but I’m stucked

JavaScript

Advertisement

Answer

I think it would be easier not to use streams:

JavaScript

The key point here is that you need to explode by genre, because each item can be in multiple genres. So, you could do something like this:

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