public static void main(
String[] args) {
Stream<Integer> nums = Stream.of(1, 2, 3, 4, 5);
nums.filter(n -> n % 2 == 1);
nums.forEach(p -> System.out.print(p));
}
//===================
In this main method, The Stream<Integer> contains 1,2,3,4,5.
The stream filter first.
Then, the same stream forEach.
the above main method will throw a IllegaStatementException. I thought the first filter statement will not affect the seecond forEach statement.
Please tell me why throw Exception.