我试图压平一个大名单:
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,但我无法展平列表。
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)
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |