编程语言
首页 > 编程语言> > # java中使用stream流合并多个List为一个List

# 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());

标签:java,stream,1303,1122,1123,List,false
来源: https://www.cnblogs.com/chengqiang521/p/16382760.html