I have a class :
public class A {
     String type;
     List<String> names;
}
Given a list of objects of this class (List<A>) how can I create a Map<String, A'> in which :
- the key is the typeString.
- the value A'is a new object of typeA, formed by merging allAinstances of the input list having the sametype- thenamesListof that new object will contain all the names of the mergedAinstances'nameslists.
I tried using toMap and groupingBy from Java Collectors framework, but toMap throws an IllegalStateException since there are duplicate keys, whereas groupingBy creates a map of the form Map<String, List<A>>, whereas I want a Map<String, A>.
 
     
     
     
     
    