fork(1) download
  1. import java.util.*;
  2. import java.util.stream.*;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. Set<Integer> foo = new HashSet<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8));
  7. System.out.println(foo);
  8. Set<Integer> bar = foo.stream()
  9. .filter(i -> i % 2 == 0)
  10. .peek(foo::remove)
  11. .collect(Collectors.toSet());
  12. System.out.println(foo);
  13. System.out.println(bar);
  14. }
  15. }
Runtime error #stdin #stdout #stderr 0.14s 4386816KB
stdin
Standard input is empty
stdout
[1, 2, 3, 4, 5, 6, 7, 8]
stderr
Exception in thread "main" java.util.ConcurrentModificationException
	at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1553)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at Main.main(Main.java:11)