Processus de tri en divisant la liste en groupes
//groupe
Map<String, List<Object>> map = list.stream().collect(//
Collectors.groupingBy(o -> o.getKey1()));
//Plusieurs clés
Map<String, List<Object>> map = list.stream().collect(//
Collectors.groupingBy(o -> o.getKey1() + o.getKey2()));
//Prend en charge plusieurs valeurs nulles clés
Map<String, List<Object>> map = list.stream().collect(//
Collectors.groupingBy(t -> t.getKey1() + (t.getKey2() == null ? "" : t.getKey2())));
//Trier
Comparator<Object> comparator = //
Comparator.comparing(Object::getSort1, Comparator.nullsFirst(Comparator.naturalOrder()))//
.thenComparing(Object::getSort2, Comparator.nullsFirst(Comparator.naturalOrder()))//
.thenComparing(Object::getSort3, Comparator.nullsFirst(Comparator.naturalOrder()));
// limit
map.entrySet().forEach(e -> e.getValue().stream().sorted(comparator).limit(100).forEach(l -> System.out.println(e.getKey() + ":" + l.getValue())));
Recommended Posts