使用stream流连接两个list

2022-08-16 17:19:27 浏览数 (1)

生命如同寓言,其价值不在于长短,而在于内容—— 塞涅卡

代码语言:javascript复制
List<Integer> integerList = Arrays.stream(new int[]{1, 2, 3}).boxed().collect(Collectors.toList());
List<Integer> collect = Stream.concat(integerList.stream(), integerList.stream()).collect(Collectors.toList());
collect.forEach(System.out::print);
System.out.println();
collect = Stream.of(integerList, integerList).flatMap(List::stream).collect(Collectors.toList());
collect.forEach(System.out::print);
System.out.println();

0 人点赞