parse Enum value - Android java.lang

Android examples for java.lang:Enum

Description

parse Enum value

Demo Code

public class Main {

  public static <T extends Enum<T>> T parseEnum(String value, Class<T> enumType) {
    if (value != null && !value.isEmpty() && enumType != null) {
      try {/*from w  w  w. j a va2s . c  o  m*/
        return Enum.valueOf(enumType, value);
      } catch (IllegalArgumentException ex) {
        return null;
      }
    } else {
      return null;
    }
  }

}

Related Tutorials