Code example for ConcurrentHashMap

Methods: putIfAbsent

0
 
public class ConcurrentUtils { 
 
	public static <K, V> V putIfAbsent(ConcurrentHashMap<K, V> map, K key,
			V value) {
		V oldV = map.putIfAbsent(key, value);
		if (oldV != null) {
			return oldV;
		} 
		return value;
	} 
}