바에서 Null 이나 빈값을 체크 할 때, StringUtils .isEmpty / .isBlank를 사용


StringUtils.isBlank ()

 StringUtils.isBlank (null)      = true
 StringUtils.isBlank ("")        = true  
 StringUtils.isBlank (" ")       = true  
 StringUtils.isBlank ("jungle")     = false  
 StringUtils.isBlank ("  jungle  ") = false


동작 방식 : StringUtils.isBlank ()


1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static boolean isBlank(String str) {
    int strLen;
 
    if (str == null || (strLen = str.length()) == 0) {
        return true;
    }
 
    for (int i = 0; i < strLen; i++) {
        if ((Character.isWhitespace(str.charAt(i)) == false)) {
            return false;
        }
    }
    return true;
}
cs



StringUtils.isEmpty

 StringUtils.isEmpty(null)      = true
 StringUtils.isEmpty("")        = true  
 StringUtils.isEmpty(" ")       = false  
 StringUtils.isEmpty("jungle")     = false  
 StringUtils.isEmpty("  jungle  ") = false


동작 방식 : StringUtils.isEmpty


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


'Back-End' 카테고리의 다른 글

String 자릿수 표현식  (0) 2019.08.05
구분값을 추가하여 데이터 합치는 로직  (0) 2019.07.19
String 문자열 조건문의로 비교시  (0) 2018.07.12

+ Recent posts