Java Utililty Methods String Empty

List of utility methods to do String Empty

Description

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

Method

StringcoerceValueIfNullOrEmpty(String s, String valueIfNullOrEmpty)
Use this when you want to normalize empty and null strings This way, Utility.areObjectsEqual can used for comparison, where a null string is to be treated the same as an empty string.
if (isNullOrEmpty(s)) {
    return valueIfNullOrEmpty;
return s;
StringemptyString()
Return an empty String (immutable).
return EMPTY_STRING;
StringemptyString(final String a, final String defaultString)
empty String
return a != null && a.length() > 0 ? a : defaultString;
booleanemptyString(final String string)
Check if a string is null , empty or contains only whitespaces.
if (string == null)
    return true;
if (string.length() < 1)
    return true;
if (string.matches("\\s+"))
    return true;
return false;
booleanemptyString(Object s)
*
return ((s == null) || ((s instanceof String) && s.equals("")));
booleanemptyString(String s)

return s == null || s.matches("(\\s)*");
booleanemptyString(String s)
Tests if a string is empty.
boolean expr = (s == null || s.length() == 0);
return expr;
booleanemptyString(String str)
Verifica se a string esta nula ou vazia
return str == null || str.trim().length() == 0;
booleanemptyString(String str)
empty String
return str == null || str.trim().length() == 0;
StringemptyString2Null(String stringValue)
empty String Null
if (stringValue != null && stringValue.length() == 0) {
    return null;
return stringValue;