# java中使用stream流合并多个List为一个List

通常我们可以使用List自带的addAll来实现;但是项目中还是多用stream()来实现;

小例子

[{"n":7373,"d":[1103,1122,1124,1123,1135],"t":1,"l":false},{"n":7374,"d":[1200,1303,1396,1437,1407],"t":1,"l":false}]

结果
[1103,1122,1124,1123,1135,1200,1303,1396,1437,1407]

先创建一个类去接收Json,再用stream里面的flatMap对数组进行扁平化处理

        List<Integer> collect = (List<Integer>) ecgResDateVos.stream().flatMap(x -> x.getD().stream()).collect(Collectors.toList());
posted @ 2022-06-16 17:23  成强  阅读(11061)  评论(0编辑  收藏  举报