Code example for CopyOnWriteArrayList

Methods: add

0
    public ConcurrentListMap() { 
        this.map = new ConcurrentHashMap<K, CopyOnWriteArrayList<V>>();
    } 
 
    public void put(K key, V value) {
        addList(key).add(value);
    } 
 
    public void putIfAbsent(K key, V value) {
        addList(key).addIfAbsent(value);
    } 
 
    private CopyOnWriteArrayList<V> addList(K key) {
        CopyOnWriteArrayList<V> list = this.map.get(key);
        if (list == null) {
            list = new CopyOnWriteArrayList<V>();
            CopyOnWriteArrayList<V> prev = this.map.putIfAbsent(key, list);
            if (prev != null) {
                list = prev;
            } 
        } 
        return list;
Experience pair programming with AI  Get Codota for Java