EnumMap clone() Method in Java Last Updated : 24 Jul, 2020 Suggest changes Share Like Article Like Report The Java.util.EnumMap.clone() method in Java is used to copy the mapped values of one map to another. It basically creates a shallow copy of this map. Syntax: Enum_map_2 = Enum_map_1.clone() Parameters: The method does not accept any argument. Return Value: The method returns a shallow copy of a EnumMap. Below programs illustrate the Java.util.EnumMap.clone() method Program 1: Java // Java program to demonstrate clone() method import java.util.*; // An enum of fruits price is created public enum Price_of_Fruits { Orange, Apple, Banana, Pomegranate, Guava }; class Enum_map { public static void main(String[] args) { EnumMap<Price_of_Fruits, Integer> mp1 = new EnumMap<Price_of_Fruits, Integer>(Price_of_Fruits.class); EnumMap<Price_of_Fruits, Integer> mp2 = new EnumMap<Price_of_Fruits, Integer>(Price_of_Fruits.class); // Values are associated in mp1 mp1.put(Price_of_Fruits.Orange, 30); mp1.put(Price_of_Fruits.Apple, 60); mp1.put(Price_of_Fruits.Banana, 40); mp1.put(Price_of_Fruits.Pomegranate, 120); mp1.put(Price_of_Fruits.Guava, 20); // Price of fruits in mp1 System.out.println("Price of fruits in 1st map " + mp1); // Copying the values of mp1 to mp2 mp2 = mp1.clone(); // Price of fruits in mp2 System.out.println("Price of fruits in 2nd map " + mp2); } } Output: Price of fruits in 1st map {Orange=30, Apple=60, Banana=40, Pomegranate=120, Guava=20} Price of fruits in 2nd map {Orange=30, Apple=60, Banana=40, Pomegranate=120, Guava=20} Program 2: Java // Java program to demonstrate clone() method import java.util.*; // An enum of gfg ranking is created public enum gfg_ranking { Global_2018, India_2018 }; class Enum_map { public static void main(String[] args) { EnumMap<gfg_ranking, Integer> mp1 = new EnumMap<gfg_ranking, Integer>(gfg_ranking.class); EnumMap<gfg_ranking, Integer> mp2 = new EnumMap<gfg_ranking, Integer>(gfg_ranking.class); // Values are associated in mp1 mp1.put(gfg_ranking.Global_2018, 800); mp1.put(gfg_ranking.India_2018, 72); // Price of fruits in mp1 System.out.println("GeeksforGeeks ranking in first map " + mp1); // Copying the values of mp1 to mp2 mp2 = mp1.clone(); // Price of fruits in mp2 System.out.println("GeeksforGeeks ranking in second map " + mp2); } } Output: GeeksforGeeks ranking in first map {Global_2018=800, India_2018=72} GeeksforGeeks ranking in second map {Global_2018=800, India_2018=72} Create Quiz A akash1295 Follow 0 Article Tags : Java Java-Collections Java-Functions Java-EnumMap Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like