I want to group a map object by key. I try with this code but i have a compile error:
Non-static method cannot be referenced from a static context
My code:
Map<String, List<A>> getAMap() {
return Arrays.stream(SomeArray.values())
.map(map -> createObject())
.collect(Collectors.groupingBy(Map.Entry::getKey,
Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
}
private Map<String, A> createObject()
final A a = new A(some attributes);
Map<String, A> map = new LinkedHashMap<>();
map.put(some key, a);
.... // add another values.
return map;
}
I need something like
{
"a", {a1, a2, a3},
"b", {a4, a5, a6},
}