Android Utililty Methods String Null Convert

List of utility methods to do String Null Convert

Description

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

Method

StringtoNonNull(String str)
to Non Null
return str == null ? "" : str;
StringtoStrNotNull(Object obj, String defaultStr)
to Str Not Null
String s = (obj == null) ? defaultStr : obj.toString();
return s;
StringconvertToNull(String chaine)
convert To Null
if ("".equals(chaine) || " ".equals(chaine)
        || "null".equals(chaine) || "NULL".equals(chaine)
        || "Null".equals(chaine)) {
    return null;
return chaine;
StringdefaultIfNull(String str)
default If Null
return defaultIfNull(str, EMPTY);
StringdefaultIfNull(String str, String defaultStr)
default If Null
return str == null ? defaultStr : str;
StringdefaultIfBlank(String str, String defaultStr)
default If Blank
return isBlank(str) ? defaultStr : str;
StringdefaultIfBlank(String str)
default If Blank
return defaultIfBlank(str, EMPTY);
booleanisEmptyOrWhitespaceOnly(String str)
is Empty Or Whitespace Only
if (TextUtils.isEmpty(str)) {
    return true;
for (int i = 0; i < str.length(); i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
        return false;
return true;
StringtoStringWhenNull(Object src, String newValue)
to String When Null
if (src == null) {
    return newValue;
String srcStr = src.toString();
if (srcStr == null) {
    return newValue;
return srcStr;
...
StringtoStringWhenNullOrEmpty(Object src, String newValue)
to String When Null Or Empty
if (src == null) {
    return newValue;
String srcStr = src.toString();
if ((srcStr == null) || (srcStr.equals(""))) {
    return newValue;
return srcStr;
...