June 2018
Beginner
722 pages
18h 47m
English
The putAll(Map<? extends K, ? extends V> map) method adds each key-value pair from the provided map the same way the put(K, V) method does for one pair:
Map<Integer, String> map1 = new HashMap<>();map1.put(1, null);map1.put(2, "s2");map1.put(3, "s3");Map<Integer, String> map2 = new HashMap<>();map2.put(1, "s1");map2.put(2, null);map2.put(4, "s4");map1.putAll(map2);System.out.println(map1); //prints: {1=s1, 2=null, 3=s3, 4=s4}
As you can see, the putAll() method adds a new pair or overrides a value in the existing pair (based on the key) and does not return anything.
Read now
Unlock full access