AbstractMap.putAll() is a method of the Java AbstractMap class. We use it to copy all the mappings from a specified AbstractMap to another AbstractMap.
The behaviour of this putAll() operation is undefined if the specified AbstractMap is modified while the operation is in progress.
AbstractMap.putAll(anExistingAbstractMap);
The AbstractMap.putAll() method takes one parameter, the existingAbstractMap, to be copied.
The method throws:
UnsupportedOperationException when the putAll() operation is not supported by the other AbstractMap.
ClassCastException when the class of a key or value in the specified AbstractMap prevents it from being stored in the other AbstractMap.
NullPointerException if the specified AbstractMap is NULL, or if the other AbstractMap does not permit NULL keys or values, and the specified AbstractMap contains NULL keys or values.
IllegalArgumentException if some property of a key or value in the specified AbstractMap prevents it from being stored in the other AbstractMap.
We can write the illustration above in the code snippet shown below.
import java.util.*;class AbstractMapDemo {public static void main(String[] args){// Creating an AbstractMapAbstractMap<Integer, String>abstractMap = new HashMap<Integer, String>();// Mapping string values to int keysabstractMap.put(21, "Shot");abstractMap.put(42, "Java");abstractMap.put(34, "Yaaaayy");// Printing the AbstractMapSystem.out.println("The Mappings are: "+ abstractMap);// Creating a new AbstractMapAbstractMap<Integer, String>newAbstractMap = new HashMap<Integer, String>();// Copying all the mappingsnewAbstractMap.putAll(abstractMap);// Printing the new AbstractMapSystem.out.println("The new AbstractMap will be: "+ newAbstractMap );}}