java - Map putAll 覆盖还是添加?

标签 java map

当我使用 .putAll() 时,另一个 .putAll() 会覆盖 map 的内容吗? 我的 map 会包含 SomeOfMyObjects 和 SomeOfMyObjects 吗?

Map<MyObject> blah = new HashMap<>();
blah.putAll('SomeOfMyObjects')
blah.putAll('SomeOfMyObjects')

谢谢!

最佳答案

If you see docs

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map.

this call is equivalent to that of calling put(k, v) 

对于 as per put() method

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

关于java - Map putAll 覆盖还是添加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17827573/

相关文章:

javascript - 在 JQVmap 中使用自定义区域

java - 如何从java中的链表中反向打印元素?

r - R中数据框中连续的字符串,列表对

C++ 遍历模板 Map

java - 获取 LinkedHashMap 中的下一项?

javascript - javascript中的map()是同步的吗?

java - 在二维数组中查找非空网格单元

java - 在Java中查找数组中的元素

java - TopCoder 使用离线可视化工具进行割草挑战

java - 计算形状的中点