putAll
just iterate the entry set of the source Map and call put (K key, V value)
for each k-v pair. Nothing special. So it behaves the same as calling put
many times in a for loop.
Read the code below and then you'll be clear.
public void putAll(Map<? extends K, ? extends V> m) {
for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
put(e.getKey(), e.getValue());
}
Edited by the OP to complete the answer:
This code proves put(key,value)
will not create a new object, but use the value argument, I just tested it and watch the variables in the debugger:
Map<String, Rect> mymap = new HashMap<String, Rect>();
Rect r1 = new Rect(0,120,200,155);
mymap.put("corner", r1);
r1.offset(20, 17);
Rect r2 = mymap.get("corner");
r1 becomes (20,137,220,172) and so is the returned value r2, proving the reference is mantained.