我明白爲什麼下面的代碼是可以的。因爲集合在調用終端操作之前正在修改。java 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。我不知道這是一個終端操作。 –