小编Nis*_*mar的帖子

使用 Stream StreamSupplier

我正在使用以下代码重用 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();
    }
}
Run Code Online (Sandbox Code Playgroud)

java arrays java-8 java-stream

5
推荐指数
1
解决办法
1258
查看次数

标签 统计

arrays ×1

java ×1

java-8 ×1

java-stream ×1