How to convert set to map with a set as the value in java 8?

Viewed 12755

I have the following class:

class A {
   private String id;
   private String name;
   private String systemid;
}

I'm getting a set of A and want to convert it to a map where the key is the system id, and the value is set of A. (Map<String, Set<A>) There can be multiple A instances with the same systemid.

Can't seem to figure out how to do it.. got till here but the identity is clearly not right

Map<String, Set<A>> sysUidToAMap = mySet.stream().collect(Collectors.toMap(A::getSystemID, Function.identity()));

can you please assist?

3 Answers
Related