ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • StringUtils - isEmpty vs isBlank 비교
    Study/Java 2022. 2. 24. 17:04

    org.apache.commons.lang3 : 3.12.0 버전 기준

     

    * StringUtils isEmpty, isBlank

    StringUtils null 공백문자("") whitespace(" ")
    isEmpty(s) true true false
    isBlank(s) true true true
    isNotEmpty(s) false false true
    isNotBlank(s) false false false
    StringUtils null 공백문자("") whitespace(" ")
    isAnyEmpty(s...) isAnyEmpty(null, "") : true true false
    param 중 empty 있으면 true isAnyEmpty(null) : false
    isAnyBlank(s...) isAnyBlank(null, "") : true true true
    param 중 blank 있으면 true isAnyBlank(null) : false
    isNoneEmpty(s...) isNoneEmpty(null, "") : false false true
    param 중 empty 있으면 false isNoneEmpty(null) : true
    isNoneBlank(s...) isNoneBlank(null, "") : false false false
    param 중 blank 있으면 false isNoneBlank(null) : true
    isAllEmpty(s...) true true false
    모든 param이 empty 면 true
    isAllBlank(s...) true true true
    모든 param이 blank 면 true
    • null, 공백문자 외 화이트스페이스 체크 시 Blank 로 체크하자.
    StringUtils.isEmpty()
    - Checks if a CharSequence is empty ("") or null.
    StringUtils.isEmpty(null)      = true
    StringUtils.isEmpty("")        = true
    StringUtils.isEmpty(" ")       = false
    StringUtils.isEmpty("bob")     = false
    StringUtils.isEmpty("  bob  ") = false
    
    
    StringUtils.isBlank()
    - Checks if a CharSequence is empty (""), null or whitespace only.
    StringUtils.isBlank(null)      = true
    StringUtils.isBlank("")        = true
    StringUtils.isBlank(" ")       = true
    StringUtils.isBlank("bob")     = false
    StringUtils.isBlank("  bob  ") = false
    
    
    StringUtils.isNotEmpty()
    - Checks if a CharSequence is not empty ("") and not null.
    StringUtils.isNotEmpty(null)      = false
    StringUtils.isNotEmpty("")        = false
    StringUtils.isNotEmpty(" ")       = true
    StringUtils.isNotEmpty("bob")     = true
    StringUtils.isNotEmpty("  bob  ") = true
         
    
    StringUtils.isNotBlank()
    Checks if a CharSequence is not empty (""), not null and not whitespace only.
    StringUtils.isNotBlank(null)      = false
    StringUtils.isNotBlank("")        = false
    StringUtils.isNotBlank(" ")       = false
    StringUtils.isNotBlank("bob")     = true
    StringUtils.isNotBlank("  bob  ") = true
    
    
    StringUtils.isAnyEmpty()
    - Checks if any of the CharSequences are empty ("") or null.
    StringUtils.isAnyEmpty((String) null)    = true
    StringUtils.isAnyEmpty((String[]) null)  = false
    StringUtils.isAnyEmpty(null, "foo")      = true
    StringUtils.isAnyEmpty("", "bar")        = true
    StringUtils.isAnyEmpty("bob", "")        = true
    StringUtils.isAnyEmpty("  bob  ", null)  = true
    StringUtils.isAnyEmpty(" ", "bar")       = false
    StringUtils.isAnyEmpty("foo", "bar")     = false
    StringUtils.isAnyEmpty(new String[]{})   = false
    StringUtils.isAnyEmpty(new String[]{""}) = true
    
    
    StringUtils.isAnyBlank()
    - Checks if any of the CharSequences are empty ("") or null or whitespace only.
    StringUtils.isAnyBlank((String) null)    = true
    StringUtils.isAnyBlank((String[]) null)  = false
    StringUtils.isAnyBlank(null, "foo")      = true
    StringUtils.isAnyBlank(null, null)       = true
    StringUtils.isAnyBlank("", "bar")        = true
    StringUtils.isAnyBlank("bob", "")        = true
    StringUtils.isAnyBlank("  bob  ", null)  = true
    StringUtils.isAnyBlank(" ", "bar")       = true
    StringUtils.isAnyBlank(new String[] {})  = false
    StringUtils.isAnyBlank(new String[]{""}) = true
    StringUtils.isAnyBlank("foo", "bar")     = false
    
    
    StringUtils.isNoneEmpty()
    - Checks if none of the CharSequences are empty ("") or null.
    StringUtils.isNoneEmpty((String) null)    = false
    StringUtils.isNoneEmpty((String[]) null)  = true
    StringUtils.isNoneEmpty(null, "foo")      = false
    StringUtils.isNoneEmpty("", "bar")        = false
    StringUtils.isNoneEmpty("bob", "")        = false
    StringUtils.isNoneEmpty("  bob  ", null)  = false
    StringUtils.isNoneEmpty(new String[] {})  = true
    StringUtils.isNoneEmpty(new String[]{""}) = false
    StringUtils.isNoneEmpty(" ", "bar")       = true
    StringUtils.isNoneEmpty("foo", "bar")     = true
    
    
    StringUtils.isNoneBlank()
    - Checks if none of the CharSequences are empty (""), null or whitespace only.
    StringUtils.isNoneBlank((String) null)    = false
    StringUtils.isNoneBlank((String[]) null)  = true
    StringUtils.isNoneBlank(null, "foo")      = false
    StringUtils.isNoneBlank(null, null)       = false
    StringUtils.isNoneBlank("", "bar")        = false
    StringUtils.isNoneBlank("bob", "")        = false
    StringUtils.isNoneBlank("  bob  ", null)  = false
    StringUtils.isNoneBlank(" ", "bar")       = false
    StringUtils.isNoneBlank(new String[] {})  = true
    StringUtils.isNoneBlank(new String[]{""}) = false
    StringUtils.isNoneBlank("foo", "bar")     = true
    
    
    StringUtils.isAllEmpty()
    - Checks if all of the CharSequences are empty ("") or null.
    StringUtils.isAllEmpty(null)             = true
    StringUtils.isAllEmpty(null, "")         = true
    StringUtils.isAllEmpty(new String[] {})  = true
    StringUtils.isAllEmpty(null, "foo")      = false
    StringUtils.isAllEmpty("", "bar")        = false
    StringUtils.isAllEmpty("bob", "")        = false
    StringUtils.isAllEmpty("  bob  ", null)  = false
    StringUtils.isAllEmpty(" ", "bar")       = false
    StringUtils.isAllEmpty("foo", "bar")     = false
    
    
    StringUtils.isAllBlank()
    - Checks if all of the CharSequences are empty (""), null or whitespace only.
    StringUtils.isAllBlank(null)             = true
    StringUtils.isAllBlank(null, "foo")      = false
    StringUtils.isAllBlank(null, null)       = true
    StringUtils.isAllBlank("", "bar")        = false
    StringUtils.isAllBlank("bob", "")        = false
    StringUtils.isAllBlank("  bob  ", null)  = false
    StringUtils.isAllBlank(" ", "bar")       = false
    StringUtils.isAllBlank("foo", "bar")     = false
    StringUtils.isAllBlank(new String[] {})  = true

     

    commons-lang/StringUtils.java at master · apache/commons-lang · GitHub

     

    GitHub - apache/commons-lang: Mirror of Apache Commons Lang

    Mirror of Apache Commons Lang. Contribute to apache/commons-lang development by creating an account on GitHub.

    github.com

     

    반응형

    'Study > Java' 카테고리의 다른 글

    StringUtils - isEmpty vs isBlank 비교  (0) 2022.02.24

    댓글 0

Designed by Tistory.