如何展平 List<List<List<String>>>

LSo*_*oft 3 java java-8

我试图压平一个大名单:

List<List<List<String>>> input
Run Code Online (Sandbox Code Playgroud)

我的清单示例:

[[[a,b],[c,b]], [[x],[y]]]`
Run Code Online (Sandbox Code Playgroud)

我希望结果如下:

[[a,b,c],[x,y]]
Run Code Online (Sandbox Code Playgroud)

对于重复项,我将尝试使用LinkedHashSet,但我无法展平列表。

Eug*_*ene 5

List<List<String>> result = 
    list.stream()
        .map(x -> x.stream()
                   .flatMap(List::stream)
                   .distinct()
                   .collect(Collectors.toList()))
        .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)