操作 | 能否写入null 返回值 |
---|---|
putIfAbsent | 否,会报错 |
computeIfAbsent | 否,不会报错 |
ConcurrentHashMap map = new ConcurrentHashMap();
System.out.println("putIfAbsent: " + map.putIfAbsent("key1", "2"));
System.out.println("putIfAbsent key1:
操作 | 能否写入null 返回值 |
---|---|
putIfAbsent | 否,会报错 |
computeIfAbsent | 否,不会报错 |
ConcurrentHashMap map = new ConcurrentHashMap();
System.out.println("putIfAbsent: " + map.putIfAbsent("key1", "2"));
System.out.println("putIfAbsent key1: