Here you can find the source of putIfAbsentAndGet(ConcurrentMap
public static <K, V> V putIfAbsentAndGet(ConcurrentMap<K, V> map, K key, V newValue)
//package com.java2s; import java.util.concurrent.ConcurrentMap; public class Main { /**// ww w . j a va 2 s .c om * If the specified key is not already associated * with a value, associate it with the given value. * And return the final value stored in the map. * * This is equivalent to * <pre> {@code * if (!map.containsKey(key)) { * map.put(key, value); * return value; * } else { * return map.get(key); * }}</pre> * * except that the action is performed atomically. */ public static <K, V> V putIfAbsentAndGet(ConcurrentMap<K, V> map, K key, V newValue) { final V old = map.putIfAbsent(key, newValue); return old != null ? old : newValue; } }