Java 8 list to nested map

后端 未结 1 1964
情书的邮戳
情书的邮戳 2021-02-08 05:07

I hava a list of Class A like

class A {
 private Integer keyA;
 private Integer keyB;
 private String text;
}

I want to transfer <

相关标签:
1条回答
  • 2021-02-08 05:45

    Seems that you just need a cascaded groupingBy:

    Map<Integer, Map<Integer,List<A>>> aMappedByKeyAAndKeyB = aList.stream()
        .collect(Collectors.groupingBy(A::getKeyA, 
                     Collectors.groupingBy(A::getKeyB)));
    
    0 讨论(0)
提交回复
热议问题