简体   繁体   English

ConcurrentHashMap的put方法如何工作?

[英]How does the put method of ConcurrentHashMap work?

public static ConcurrentHashMap<String,Integer> playersPvpKills = new ConcurrentHashMap<>();

String(key) is player name Integer is the kills(of a game :P ) String(key)是玩家名称Integer是游戏的杀戮(P:P)

well if I use playersPvpKills.add("stackoverflow25", 265); 好吧,如果我使用playersPvpKills.add("stackoverflow25", 265);

If already exist key stackoverflow25 but has another amount of kills, will it automatically update it to 265? 如果已经存在密钥stackoverflow25,但还有其他原因,它将自动将其更新为265吗?

From the Javadoc for Map.put 从Javadoc for Map.put

If the map previously contained a mapping for the key, the old value is replaced by the specified value. 如果该映射先前包含该键的映射,则旧值将替换为指定值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM