gpt4 book ai didi

java - Map putAll 覆盖还是添加?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:34:36 26 4
gpt4 key购买 nike

当我使用 .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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com