O java.util.HashMap.putAll() é um método embutido da classe HashMap que é usado para a operação de cópia. O método copia todos os elementos, ou seja, os mapeamentos, de um mapa para outro.

Sintaxe:

new_hash_map.putAll(exist_hash_map)

Parâmetros: o método usa um parâmetro exist_hash_map que se refere ao mapa existente do qual queremos copiar.

Valor de retorno: O método não retorna nenhum valor.

Exceção: o método lança NullPointerException se o mapa do qual queremos copiar for NULL.

Os programas abaixo ilustram o funcionamento do método java.util.HashMap.putAll():
Programa 1: Mapeando Valores de String para Chaves Inteiras.

// Java code to illustrate the putAll() method
import java.util.*;
  
public class Hash_Map_Demo {
public static void main(String[] args) {
      
    // Creating an empty HashMap
    HashMap<Integer, String> hash_map = new HashMap<Integer, String>();
  
    // Mapping string values to int keys 
    hash_map.put(10, "Geeks");
    hash_map.put(15, "4");
    hash_map.put(20, "Geeks");
    hash_map.put(25, "Welcomes");
    hash_map.put(30, "You");
  
    // Displaying the HashMap
    System.out.println("Initial Mappings are: " + hash_map);
  
    // Creating a new hash map and copying
    HashMap<Integer, String> new_hash_map = new HashMap<Integer, String>();
    new_hash_map.putAll(hash_map);
  
    // Displaying the final HashMap
    System.out.println("The new map looks like this: " + new_hash_map);
}
}
Saída:
Os mapeamentos iniciais são: {20 = Geeks, 25 = Welcome, 10 = Geeks, 30 = You, 15 = 4}
O novo mapa tem a seguinte aparência: {25 = Boas-vindas, 10 = Geeks, 20 = Geeks, 30 = You, 15 = 4}

Programa 2: Mapeamento de valores inteiros para chaves de string.

// Java code to illustrate the putAll() method
import java.util.*;
  
public class Hash_Map_Demo {
    public static void main(String[] args)
    {
  
        // Creating an empty HashMap
        HashMap<String, Integer> hash_map = new HashMap<String, Integer>();
  
        // Mapping int values to string keys
        hash_map.put("Geeks", 10);
        hash_map.put("4", 15);
        hash_map.put("Geeks", 20);
        hash_map.put("Welcomes", 25);
        hash_map.put("You", 30);
  
        // Displaying the HashMap
        System.out.println("Initial Mappings are: " + hash_map);
  
        // Creating a new hash map and copying
        HashMap<String, Integer> new_hash_map = new HashMap<String, Integer>();
        new_hash_map.putAll(hash_map);
  
        // Displaying the final HashMap
        System.out.println("The new map looks like this: " + new_hash_map);
    }
}
Saída:
Os mapeamentos iniciais são: {4 = 15, Geeks = 20, You = 30, Welcome = 25}
O novo mapa é parecido com este: {Geeks = 20, 4 = 15, You = 30, Welcome = 25}

Nota: A mesma operação pode ser realizada com qualquer tipo de mapeamento com variação e combinação de diferentes tipos de dados.