Java Collection Tutorial - Java EnumMap(Map < K ,? extends V > m) Constructor


EnumMap(Map < K ,? extends V > m) constructor from EnumMap has the following syntax.

public EnumMap(Map <K ,? extends V> m)


In the following code shows how to use EnumMap.EnumMap(Map < K ,? extends V > m) constructor.

//  w w w. j  av a2  s.  com

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

enum Tutorial{CSS, Python, PHP, Java, Javascript}; 

public class Main {
   public static void main(String[] args) {
     Map m = new HashMap<Tutorial,String>();
      EnumMap<Tutorial,String>  map = 
              new EnumMap<Tutorial,String> (m);

      map.put(Tutorial.CSS, "1");
      map.put(Tutorial.Python, "2");
      map.put(Tutorial.Java, "4");

The code above generates the following result.