import java.util.*; class Example{ public static void main (String[] args) throws java.lang.Exception { var routingTable = new ArrayList<String>(); routingTable.add("one"); routingTable.add("two"); routingTable.add("three"); synchronized (routingTable) { for (String entry : routingTable) { if (entry.equals("two")) { routingTable.add("four"); } } } }}
Standard input is empty
Standard output is empty
Exception in thread "main" java.util.ConcurrentModificationException at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1042) at java.base/java.util.ArrayList$Itr.next(ArrayList.java:996) at Example.main(Main.java:12)
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!