get enums by class name

    /**
     * get a list of sort enum names by enum class
     * @param c  enum class
     * @return
     */
    public static List<String> enumsToSortedList(Class c){
        if(!c.isEnum()){
            return null;
        }
        Object[] objects = c.getEnumConstants();
        List<String> result = new ArrayList<String>();
        for (Object o : objects){
            result.add(o.toString());
        }
        Collections.sort(result);
        return result;
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s