Map putAll overrides or adds?

It behaves just like calling put(k,v) for every entry in the argument map, so it adds, retaining whatever is already in the map. If the same key k is added again, its value v is overwritten. putAll() tries to optimize the bulk-add by first expanding the map internally to accommodate the new data, as to avoid intermediate resizing/rehashing operations.


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) 

And for 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.)

Tags:

Java

Map