我正在使用以下代码重用 Stream 但得到
java.lang.IllegalStateException: 流已经被操作或关闭
代码
public static void main(String[] args) {
try {
String[] array = { "a", "b", "c", "d", "e" };
Stream<String> ss = Stream.of(array);
Supplier<Stream<String>> streamSupplier = () -> ss;
long count = streamSupplier.get().count();
// get new stream
streamSupplier.get().forEach(x -> System.out.println(x));
// get another new stream
System.out.println(count);
} catch (Exception e) {
e.printStackTrace();
}
}
胡子哥哥
一只甜甜圈
尚方宝剑之说
相关分类