I have a list of Objects that I want to convert into a hash map. Is it possible to create a hash-map of this type Map<String, Map<String, List<Object>>?
The reason for this is that I need to sort these by some properties in the objects so i can iterate through it later. So below is Json of what the objects currently look like:
[
object1: {plan: "11", relationship: "A", etc...},
object2: {plan: "12", relationship: "A", etc...},
object3: {plan: "11", relationship: "B", etc...},
]
I was trying to use Collectors to get it into a HashMap but i am confused on the second hash map, I can't seem to get the list of relationships into a Map.
Map<String, Map<String, List<myObject>> myHash = objectList
.stream()
.collect(Collectors.toMap(myObject::plan,
a -> a.stream().collect(Collectors.groupingBy(myObject::relationship))));
What I want to get is something like this
[
{
key: "11",
value: [
{key: "A", value: [ object1 ]},
{key: "B", value: [ object3 ]}
]
},
{
key: "12",
value: [{key: "A", value: [ object2 ]}]
}
]