The difference between isEmpty and isBlank

isEmpty   judges whether a string is empty. The standard for being empty is str==null or str.length()==0

    StringUtils.isEmpty(null) = true

  StringUtils.isEmpty("") = true
  StringUtils.isEmpty(" " ) = false//Note that spaces are treated as non-empty in 
  StringUtils StringUtils.isEmpty(" ") = false
  StringUtils.isEmpty("bob") = false
  StringUtils.isEmpty(" bob ") = false

isBlank    determines whether a string is Empty or length 0 or consisting of whitespace

   StringUtils.isBlank(null) = true

  StringUtils.isBlank("") = true
  StringUtils.isBlank(" ") = true
  StringUtils.isBlank(" ") = true
  StringUtils. isBlank("\t \n \f \r") = true //For tabs, newlines, form feeds and carriage returns 
  StringUtils. 
  StringUtils.isBlank("\b") = false //"\b" is the word boundary character 
  StringUtils.isBlank("bob") = false
  StringUtils.isBlank("bob ") = false

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326178610&siteId=291194637