I have the following class:
public class A{
public List<String> groups;
}
and I'm trying to build a Map<String, List<A>> where the key represents the group.
I know how to do when class A belongs to a single group:
List<A> aList = getAList();
Map<String, List<A>> aByGroupMap = aList.stream().parallel()
.collect(Collectors.groupingBy(a -> a.getGroup()));
But how can I adapt the above code in such a way that an object A is mapped to multiple groups?
E.g. what if object a1 belongs to the groups ["G", "H", "I"] and object a2 belongs to the groups ["H", "I"] ?