Convert String As Enum Type - Java java.lang

Java examples for java.lang:String Parse

Description

Convert String As Enum Type

Demo Code


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main{

    public static final <E extends Enum<E>> Object getAsEnumType(
            String valueAsString, Class<E> type) throws Exception {
        Object result = null;//from w w w . j av a2s  . co m

        if ((valueAsString != null) && (!valueAsString.isEmpty())
                && (type != null)) {
            result = Enum.valueOf(type, valueAsString);
        }

        return result;
    }
}

Related Tutorials