上級 › stream has already been operated upon の原因と直し方 › パターン1
stream has already been operated upon の原因と直し方
Streamは1回しか終端操作できません。
1 import java.util.List; 2 import java.util.stream.Stream; 3 4 public class Main { 5 public static void main(String[] args) { 6 Stream<Integer> s = List.of(1, 2, 3).stream(); 7 System.out.println(s.count()); 8 System.out.println(_________________________.count()); ^ 9 } 10 }
Exception in thread "main" java.lang.IllegalStateException:
stream has already been operated upon or closedexited with code 1
空欄を埋めてビルドを通す
Streamは1回しか終端操作できません。使い回さず、必要なたびに作り直します。
次の問題