Java Utililty Methods String Empty to Null

List of utility methods to do String Empty to Null

Description

The list of methods to do String Empty to Null are organized into topic(s).

Method

StringemptyStringToNull(String input)
empty String To Null
if (input.trim().equals("")) {
    return null;
} else {
    return input.trim();
StringemptyStringToNull(String str)
empty String To Null
return str == null || str.equals("") ? null : str;
StringemptyStringToNull(String string)
Returns null, if the specified string is null or the empty string.
return isEmptyOrNull(string) ? null : string;
StringemptyToDefault(String value, String def)
empty To Default
return (value == null || value.length() == 0) ? def : value;
T[]emptyToDefault(T[] values, T[] def)
empty To Default
return values == null || values.length == 0 ? def : values;
StringemptyToNull(final String text, final boolean doTrim)
Returns null if a string variable is empty.
if (doTrim && (text != null)) {
    return ("".equals(text.trim())) ? null : text;
} else {
    return ("".equals(text)) ? null : text;
StringemptyToNull(String field)
empty To Null
return "".equals(field) ? null : field;
StringemptyToNull(String s)
empty To Null
if (s == null || s.length() == 0)
    return null;
String trimmed = trim(s);
return (trimmed.length() != 0 ? s : null);
StringemptyToNull(String s)
Converts a 0-length string to null, leaves the string as is otherwise.
if (s == null)
    return null;
return s.length() == 0 ? null : s;
StringemptyToNull(String str)
Returns the given string if it is nonempty; null otherwise.
return (str == null || str.length() == 0) ? null : str;