Difference between isempty method and isblank method in stringutils

preface
When we say a string is empty, it’s just an empty array with no characters. Such as:

String a = "";

A can be called an empty string. Since String is stored as a char array underneath Java, the null String is represented as a char array

private final char value[] = new char[0];

But in actual work, we need to do some validation on the string, such as: whether null, whether null, whether to remove Spaces, line breaks, TAB characters and so on is not empty. We usually make these judgments through the framework’s utility classes, such as the Apache Commons JAR package. Here are two common string validation methods and their differences.
PS: in the process of writing project, recently found that a lot of places to be sentenced to empty operation, then can sometimes be invocation chain is longer, if use the if the else come to empty, empty code will be more light, this is not good for later maintenance, and we found empty may not consider a scene, this will result in a null pointer. I now strongly recommend using the third party JAR’s utility classes to do this. For example, take the value of a key from a Map, you can use MapUtils class; Use the StringUtils class for nulling strings; Nulling a collection using CollectionUtils and so on. These classes are available through the introduction of apache’s Commons package family.
isEmpty()

public static boolean isEmpty(String str) {        
    return str == null || str.length() == 0;
}

isBlank()

public static boolean isBlank(String str) {
        int strLen;
        if (str != null && (strLen = str.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {    
                    return false;
                }
            }
            return true;
        } else {
            return true;
        }
    }

conclusion
Through the comparison of the above codes, we can see:
1. IsEmpty does not ignore the space parameter, based on whether it isEmpty and whether it exists.

2. IsBlank is a judgment on isEmpty (strings are Spaces, tabs, TAB) based on isEmpty. (more commonly used)

you can look at the following example to feel.

StringUtils.isEmpty("yyy") = false
StringUtils.isEmpty("") = true
StringUtils.isEmpty("   ") = false
 
StringUtils.isBlank("yyy") = false
StringUtils.isBlank("") = true
StringUtils.isBlank("   ") = true

Read More: