Create new Enum Map - Java java.util

Java examples for java.util:Collection Creation

Description

Create new Enum Map

Demo Code


//package com.java2s;

import java.util.EnumMap;

import java.util.Map;

public class Main {
    public static void main(String[] argv) {
        Class keyType = String.class;
        System.out.println(newEnumMap(keyType));
    }/*w ww  .  j a  va  2  s  .c o  m*/

    public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(
            final Class<K> keyType) {
        return new EnumMap<K, V>(keyType);
    }

    public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(
            final EnumMap<K, ? extends V> m) {
        return new EnumMap<K, V>(m);
    }

    public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(
            final Map<K, ? extends V> m) {
        return new EnumMap<K, V>(m);
    }
}

Related Tutorials