Well, the oracle example here is self explanatory. The first one is:
List<String> l = new ArrayList<>(Arrays.asList("one", "two"));
Stream<String> sl = l.stream();
l.add("three");
String s = l.collect(Collectors.joining(" "));
If you change lby adding a few more elements to it before calling the terminal ( Collectors.joining) operation , you are fine; but note that it Streamconsists of three elements, not two; at the time you created Stream through l.stream().
On the other hand:
List<String> list = new ArrayList<>();
list.add("test");
list.forEach(x -> list.add(x));
will be thrown out ConcurrentModificationException, since you cannot change the source.
, , :
ConcurrentHashMap<String, Integer> cMap = new ConcurrentHashMap<>();
cMap.put("one", 1);
cMap.forEach((key, value) -> cMap.put(key + key, value + value));
System.out.println(cMap);
? , :
{oneoneoneoneoneoneoneone=8, one=1, oneone=2, oneoneoneone=4}
zx (cMap.put("zx", 1)), :
{zxzx=2, zx=1}
.