Here you can find the source of getOptionsFromEnum(Class extends Enum>> enumClass)
Parameter | Description |
---|---|
enumClass | the enum class |
public static Map<String, String> getOptionsFromEnum(Class<? extends Enum<?>> enumClass)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { /**//from ww w .j a v a 2 s. c o m * Get the label and value for select options of forms from the given enum class. * * @param enumClass the enum class * @return a map of label and value */ public static Map<String, String> getOptionsFromEnum(Class<? extends Enum<?>> enumClass) { Map<String, String> map = new HashMap<String, String>(); Enum<?>[] enumConstants = enumClass.getEnumConstants(); for (Enum<?> enumConstant : enumConstants) { map.put(enumConstant.toString(), getLabel(enumConstant.toString())); } return map; } /** * Get the label from the given value. * * @param value the value * @return the label */ private static String getLabel(String value) { return value.substring(0, 1).toUpperCase() + value.substring(1); } }