EnumMap putAll(map) Method in Java
The Java.util.EnumMap.putAll(map) method in Java is used to copy all the mappings from one map to a newer one. Older mappings are replaced in a newer one.
Syntax:
void putAll(map)
Parameters: The method takes one parameter map. It is the map which is to be copied to the newer one.
Return Value The method does not return any value.
Below programs illustrate the putAll() method:
Program 1:
// Java program to demonstrate keySet() import java.util.*; // An enum of geeksforgeeks public enum gfg { Global_today, India_today, China_today }; class Enum_demo { public static void main(String[] args) { EnumMap<gfg, Integer> mp1 = new EnumMap<gfg, Integer>(gfg.class); EnumMap<gfg, Integer> mp2 = new EnumMap<gfg, Integer>(gfg.class); // Values are associated mp1.put(gfg.Global_today, 799); mp1.put(gfg.India_today, 69); // Copies all the mappings of mp1 to mp2 mp2.putAll(mp1); // Prints the first map System.out.println("Mappings in Map1: " + mp1); // Prints the second map System.out.println("Mappings in Map2: " + mp2); } } |
chevron_right
filter_none
Output:
Mappings in Map1: {Global_today=799, India_today=69}
Mappings in Map2: {Global_today=799, India_today=69}
Program 2:
// Java program to demonstrate the working of keySet() import java.util.*; // an enum of geeksforgeeks // visitors in India and United States public enum gfg { India_today, United_States_today } ; class Enum_demo { public static void main(String[] args) { EnumMap<gfg, String> mp1 = new EnumMap<gfg, String>(gfg.class); EnumMap<gfg, String> mp2 = new EnumMap<gfg, String>(gfg.class); // Values are associated mp1.put(gfg.India_today, "61.8%"); mp1.put(gfg.United_States_today, "18.2%"); // Copies all the mappings of mp1 to mp2 mp2.putAll(mp1); // Prints the first map System.out.println("Mappings in Map1: " + mp1); // Prints the second map System.out.println("Mappings in Map2: " + mp2); } } |
chevron_right
filter_none
Output:
Mappings in Map1: {India_today=61.8%, United_States_today=18.2%}
Mappings in Map2: {India_today=61.8%, United_States_today=18.2%}
Recommended Posts:
- EnumMap put() Method in Java
- EnumMap get() Method in Java
- EnumMap keySet() Method in Java
- EnumMap remove() Method in Java
- EnumMap size() Method in Java
- EnumMap values() Method in Java
- EnumMap containsValue(value) method in Java
- EnumMap clone() Method in Java
- EnumMap entrySet() Method in Java
- EnumMap containsKey() Method in Java
- EnumMap clear() Method in Java with Examples
- EnumMap equals() Method in Java with Examples
- EnumMap class in Java
- Java.lang.Short toString() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



