다음 코드가 올바른 이유를 이해합니다. 터미널 작업을 호출하기 전에 컬렉션이 수정되기 때문입니다.자바 8 스트림 간섭 대 비 간섭
List<String> wordList = ...;
Stream<String> words = wordList.stream();
wordList.add("END"); // Ok
long n = words.distinct().count();
하지만이 코드는 왜 잘못 되었습니까?
Stream<String> words = wordList.stream();
words.forEach(s -> if (s.length() < 12) wordList.remove(s)); // Error—interference
Thx. 나는 터미널 작전 이었다는 것을 몰랐다. –