s-day07--Stream流中的常用方法_concat
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.inmind.stream03;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/*
|
||||
28.Stream流中的常用方法_concat
|
||||
static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
|
||||
合并2个流,生成一个新的流
|
||||
*/
|
||||
public class ConcatDemo15 {
|
||||
public static void main(String[] args) {
|
||||
Stream<Integer> stream1 = Stream.of(1, 2, 3, 4, 5);
|
||||
Stream<Integer> stream2 = Stream.of(6, 7, 8, 9, 10);
|
||||
//将2个流合并,得到1~10的数据
|
||||
Stream<Integer> newStream = Stream.concat(stream1, stream2);
|
||||
System.out.println(newStream.count());//10
|
||||
// newStream.forEach(i-> System.out.println(i));
|
||||
//java.lang.IllegalStateException: stream has already been operated upon or closed
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user