Код: Выделить всё
Stream stream = Stream.of(1, 2, 3, 4, 5);
stream.forEach((e) -> {
System.out.println("inside for Each");
if(e == 3) {
stream.close();
} else {
System.out.println(e);
}
});
< /code>
Я ожидал следующего вывода: < /p>
inside for Each
1
inside for Each
2
inside for Each
< /code>
Но я получил следующий вывод: < /p>
inside for Each
1
inside for Each
2
inside for Each
inside for Each
4
inside for Each
5
Подробнее здесь: https://stackoverflow.com/questions/638 ... ing-stream