这个方法在key不存在的时候加入一个值,如果key存在就不放入,等价: if (!map.containsKey(key)) return map.put(key, value); else return map.get(key); 测试代码: public class Test { public static void main(String[] args) { ConcurrentHashMap<String,String> map=new ConcurrentHashMap<Str…
putIfAbsent 源代码 public V putIfAbsent(K key, V value) { Segment<K,V> s; if (value == null) throw new NullPointerException(); int hash = hash(key); int j = (hash >>> segmentShift) & segmentMask; if ((s = (Segment<K,V>)UNSAFE.getObje…