Android Utililty Methods String Empty Check

List of utility methods to do String Empty Check

Description

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

Method

booleanisEmpty(String string)
is Empty
if (string == null) {
    return true;
if ("".equals(string)) {
    return true;
return false;
booleanisEmptyString(String s)
is Empty String
return s.trim().length() == 0;
booleanisEmptyOrNull(String str)
is Empty Or Null
return str == null || str.length() == 0
        || str.contentEquals("null") || str.trim().equals("");
StringtoNullIfEmptyOrWhitespace(String string)
Returns the given string if it is nonempty and contains at least one non-whitespace character; null otherwise.
return isEmptyOrWhitespace(string) ? null : string;
StringtoNullIfEmpty(String string)
Old location of Strings#emptyToNull ; this method will be deprecated soon.
return Strings.emptyToNull(string);
booleanisNullOrEmptyOrOnlyWhitespaces(String string)
Checks is string null or its length == 0 or it contains only whitespaces, very useful
return isNullOrEmpty(string) ? true : string.trim().length() == 0;
StringnullToEmpty(String url)
Use to normalize URL parameters by returning empty string instead of null or "null".
if (null == url || url.equals(NULL))
    return EMPTY;
return url;
booleanisEmpty(String s)
Check if string is null or empty.
if (null == s || s.trim().equals(EMPTY) || s.trim().equals(NULL))
    return true;
return false;
booleanisEmpty(String s)
Implement an isEmpty for API < 9
return s == null || s.length() == 0;
booleanisEmpty(String str)
is Empty
return str == null || str.length() == 0;