StringUtils tool class distinction of isBlank () method and isEmpty () method

1.isBlank () method

Public static Boolean of isBlank. 1 (String str) { 
 2 int strLen; 
 . 3 IF (str == null || (strLen = str.length ()) == 0) {// determines whether str is null or is equal to the length of str 0 
 return to true. 4; 
 . 5} 
 . 6 for (int I = 0; I <strLen; I ++) { 
 . 7 IF ((Character.isWhitespace (str.charAt (I)) == to false)) {// whitespace Analyzing 
 8 return to false; 
 . 9} 
10} 
. 11 return to true; 
12 is}

2.isEmpty () method

Public static Boolean isEmpty. 1 (String str) { 
2 str.length return str == null || () == 0; // determines whether it is null or str str length equals zero 
3}

It can be seen of isBlank () method and isEmpty () the biggest difference is determined whether or not there is a blank character string in the

public static void main(String[] args) {
        System.out.println(StringUtils.isBlank("  "));    //true
System.out.println(StringUtils.isEmpty(" "));    //flase
    }

Guess you like

Origin www.cnblogs.com/coder-wf/p/12127757.html