标签:concurrenthashmap putifabsent
putIfAbsent:
当key不存在的时候调用put方法将key存入进map
当key存在的时候相当于return map.get(key)
public static void main(String[] args) { ConcurrentHashMap map = new ConcurrentHashMap(); Object o = map.putIfAbsent("aaa", "bbb"); System.out.println("111"+o); Object o1 = map.putIfAbsent("aaa", "bbb"); System.out.println("222"+o1); }
输出
111null
222bbb
put
与之hashMap相同,当key存在时,put同样的key将被覆盖
本文出自 “幕后黑手” 博客,请务必保留此出处http://11942699.blog.51cto.com/11932699/1882402
ConcurrentHashMap putIfAbsent和的put区别
标签:concurrenthashmap putifabsent
原文地址:http://11942699.blog.51cto.com/11932699/1882402