put to ConcurrentMap If Absent - Java java.util

Java examples for java.util:Map Entry

Description

put to ConcurrentMap If Absent

Demo Code


//package com.java2s;

import java.util.concurrent.ConcurrentMap;

public class Main {

    public static <K, V> V putIfAbsent(final ConcurrentMap<K, V> map,
            final K key, final V value) {
        final V exists = map.putIfAbsent(key, value);
        if (exists != null) {
            return exists;
        }/*from   w w w .ja  va2 s.c  o m*/
        return value;
    }
}

Related Tutorials