Java EnumMap.clone()

Syntax

EnumMap.clone() has the following syntax.

public EnumMap <K , V> clone()

Example

In the following code shows how to use EnumMap.clone() method.


/* ww  w. ja  v a  2 s .  c om*/
import java.util.EnumMap;

enum Tutorial {

   CSS, Python, PHP, Java, Javascript
};
public class Main {


   public static void main(String[] args) {
      EnumMap<Tutorial, String>  map1 =
              new EnumMap<Tutorial, String> (Tutorial.class);
      EnumMap<Tutorial, String>  map2 =
              new EnumMap<Tutorial, String> (Tutorial.class);

      map1.put(Tutorial.CSS, "1");
      map1.put(Tutorial.Python, "2");
      map1.put(Tutorial.PHP, "3");
      map1.put(Tutorial.Java, "4");

      System.out.println("map1:" + map1);

      map2 = map1.clone();

      System.out.println("map2:" + map2);
   }
}

The code above generates the following result.