Java String Value Of valueOf(Class en, String name)

Here you can find the source of valueOf(Class en, String name)

Description

Gets the value of an enum from a name.

License

LGPL

Parameter

Parameter Description
en enum
name name of item

Return

value or null

Declaration

public static <T extends Enum<T>> T valueOf(Class<T> en, String name) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//from   w  w  w . j  ava 2  s  .  co  m
     * Gets the value of an enum from a name. The name can be null, causing
     * the return value to be null.
     * 
     * @param en enum
     * @param name name of item
     * @return value or null
     */
    public static <T extends Enum<T>> T valueOf(Class<T> en, String name) {
        if (name == null)
            return null;
        try {
            return Enum.valueOf(en, name);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }
}

Related

  1. valueOf(Class cls, String s)
  2. valueOf(Class enumType, String constantName)
  3. valueOf(Class enumType, String name)
  4. valueOf(Class enumType, String name)
  5. valueOf(Class enumType, String name)