In Java the StringUtils tool class resolves the judgment that String is null

  • 2020-12-20 03:33:08
  • OfStack

The criterion for determining whether a string is null is str==null or str.length ()==0

1. The following is an example of StringUtils judging whether it is empty:


  StringUtils.isEmpty(null) = true
  StringUtils.isEmpty("") = true
  StringUtils.isEmpty(" ") = false // Note that in  StringUtils  The space in is treated as non-null 
  StringUtils.isEmpty("  ") = false
  StringUtils.isEmpty("bob") = false
  StringUtils.isEmpty(" bob ") = false

2. public static boolean isNotEmpty(String str)

Determines whether a string is non-null, equal to! isEmpty(String str)

Here is an example:


StringUtils.isNotEmpty(null) = false
  StringUtils.isNotEmpty("") = false
  StringUtils.isNotEmpty(" ") = true
  StringUtils.isNotEmpty("     ") = true
  StringUtils.isNotEmpty("bob") = true
  StringUtils.isNotEmpty(" bob ") = true

3. public static boolean isBlank(String str)

Determines whether a string is null or has a length of 0 or consists of a blank character (whitespace)

Here is an example:


StringUtils.isBlank(null) = true
  StringUtils.isBlank("") = true
  StringUtils.isBlank(" ") = true
  StringUtils.isBlank("    ") = true
  StringUtils.isBlank("\t \n \f \r") = true  // For tabs, line feeds, page breaks, and carriage returns 
  StringUtils.isBlank()  // Recognition is a blank character 
  StringUtils.isBlank("\b") = false  //"\b" Is the word boundary character 
  StringUtils.isBlank("bob") = false
  StringUtils.isBlank(" bob ") = false

4. public static boolean isNotBlank(String str)

Determines whether a string is not null and has a length of 0 and is not formed by a blank character (whitespace), equal to! isBlank(String str)

Here is an example:


StringUtils.isNotBlank(null) = false
  StringUtils.isNotBlank("") = false
  StringUtils.isNotBlank(" ") = false
  StringUtils.isNotBlank("     ") = false
  StringUtils.isNotBlank("\t \n \f \r") = false
  StringUtils.isNotBlank("\b") = true
  StringUtils.isNotBlank("bob") = true
  StringUtils.isNotBlank(" bob ") = true

conclusion

This is all about the StringUtils tool class in Java for String null judgment parsing, I hope to help you. Interested friends can continue to refer to other related topics in this site, if there is any deficiency, welcome to comment out. Thank you for your support!


Related articles: