Java Utililty Methods String Value Of

List of utility methods to do String Value Of

Description

The list of methods to do String Value Of are organized into topic(s).

Method

TvalueOf(Class cls, String s)
value Of
try {
    return Enum.valueOf(cls, s);
} catch (IllegalArgumentException e) {
s = s.toLowerCase();
T theOne = null;
for (T value : cls.getEnumConstants()) {
    if (value.toString().toLowerCase().startsWith(s)) {
...
TvalueOf(Class en, String name)
Gets the value of an enum from a name.
if (name == null)
    return null;
try {
    return Enum.valueOf(en, name);
} catch (IllegalArgumentException e) {
    return null;
TvalueOf(Class enumType, String constantName)
This works like Enum#valueOf(Class,String) but returns null if constant wasn't found instead of throwing an IllegalArgumentException.
try {
    T constant = Enum.valueOf(enumType, constantName);
    return constant;
} catch (IllegalArgumentException ex) {
    return null;
TvalueOf(Class enumType, String name)
value Of
return valueOf(enumType, name, null);
TvalueOf(Class enumType, String name)
value Of
return valueOf(enumType, name, null);
TvalueOf(Class enumType, String name)
Null-safe valueOf function
if (name == null) {
    return null;
return Enum.valueOf(enumType, name);
TvalueOf(Class enumType, String name, T defaultValue)
value Of
try {
    return Enum.<T>valueOf(enumType, name);
} catch (Exception e) {
    return defaultValue;
EnumvalueOf(final Class enumType, final String value)
Convert a string to an enum.
return Enum.valueOf((Class<Enum>) enumType, value);
ObjectvalueOf(final Class type, final String value)
Convert a string value to a boxed primitive type.
if (type == String.class) {
    return value;
if (type == boolean.class) {
    return Boolean.valueOf(value);
if (type == int.class) {
    return Integer.valueOf(value);
...
EvalueOf(final Class clazz, final String name)
value Of
if (clazz == null) {
    return null;
final E[] es = clazz.getEnumConstants();
for (final E e : es) {
    if (e.name().equalsIgnoreCase(name)) {
        return e;
return null;