Example
Transfer entries from one map to another.
import java.util.HashMap;
public class Main {
public static void main(String[] args ) {
HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities .put("England", "London");
capitalCities .put("Germany", "Berlin");
capitalCities .put("Norway", "Oslo");
capitalCities .put("USA", "Washington DC");
HashMap<String, String> moreCities = new HashMap<String, String>();
moreCities .put("Canada", "Ottawa");
moreCities .put("Japan", "Tokyo");
capitalCities .putAll(moreCities );
System.out .println(capitalCities );
}
}
|
Definition and Usage
The putAll() method copies all entries from another map into the current map. If entries with the same keys exist, their values will be overwritten.
Syntax
Any of the following:
public void putAll(Map map)
|
K and V denote the data types of the keys and values in the map.
Parameter Values
Parameter
|
Description
|
map
|
Required: Another map containing entries to be added to the current map.
|
Technical Details
throws:
|
NullPointerException: If the provided map argument is null.
|