I have List<Person>
where Person
is as below.
class Person {
String personId;
LocalDate date;
String type;
// getters & setters
}
I'm trying to convert this to List<Person>
to Map<String, Map<LocalDate,List<Person>>>
where outer map's key is personId
and inner map's key is date
and I couldn't figure out how to achieve this.
Thus far have tried something like below. Open to Java 8 solutions as well.
Map<String,Map<LocalDate,List<Person>>> outerMap = new HashMap<>();
Map<LocalDate,List<Person>> innerMap = new HashMap<>();
for(Person p : list) {
List<Person> innerList = new ArrayList<>();
innerList.add(p);
innerMap.put(p.getDate(), innerList);
outerMap.put(p.getPersonId(), innerMap);
}