Java 8 list to nested map

后端 未结 1 1963
情书的邮戳
情书的邮戳 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>> aMappedByKeyAAndKeyB = aList.stream()
        .collect(Collectors.groupingBy(A::getKeyA, 
                     Collectors.groupingBy(A::getKeyB)));
    

    0 讨论(0)
提交回复
热议问题