how to grouping and maxBy (list of maps)

1) list of maps : 

f:id:annazola:20190701011158p:plain

sample list of maps

2) grouping and maxBy

 

f:id:annazola:20190701011524p:plain

main codes

3) before and results

 

f:id:annazola:20190701012001p:plain

 

 appendix) to copy

 

List<Optional<Map<String, Object>>>  aggrList = 

mockList.stream().collect(Collectors.groupingBy(p -> (String)p.get("niveau_1")+ (String)p.get("niveau_2")+(String)p.get("franchise"),

Collectors.maxBy(Comparator.comparingLong(p->Long.valueOf(p.get("cnt").toString())))))

.values().stream().collect(Collectors.toList());

 

List<Map<String, Object>>  endList= new ArrayList<>();

aggrList.stream().forEach(s->{

endList.add(s.get());

});

System.out.println("result list");

endList.stream().forEach(System.out::println);