import java.util.*;
import java.util.concurrent.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        //var map = new HashMap<Long, Object>(); // throws ConcurrentModificationException
        //var map = Collections.synchronizedMap(new HashMap<Long, Object>()); // throws ConcurrentModificationException
        var map = new ConcurrentHashMap<Long, Object>();
        map.put(1L, new Object());
        map.put(2L, new Object());
        for (long key : map.keySet()) {
            map.put(3L, new Object());
        }
        System.out.println("Map size: " + map.size());
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: