Determine whether the string and object are empty

Time:2021-4-18

Stringutils provides two common methods for judging empty stringsisEmptyandisBlank

  1. public static boolean isEmpty(String str)
    To determine whether a string is empty, the standard is strNull or str.length ()0
    Here is an example:
StringUtils.isEmpty (null) =  trueStringUtils.isEmpty ("") = true  StringUtils.isEmpty (') = false // note that spaces are not null in stringutils StringUtils.isEmpty ("   ") =  falseStringUtils.isEmpty ("bob") =  falseStringUtils.isEmpty (" bob ") = false
  1. public static boolean isNotEmpty(String str)
    Determine whether a string is not empty, equal to! Isempty (string STR)
    Here is an example:
StringUtils.isNotEmpty(null) = falseStringUtils.isNotEmpty("") = falseStringUtils.isNotEmpty(" ") = trueStringUtils.isNotEmpty("         ") = trueStringUtils.isNotEmpty("bob") = trueStringUtils.isNotEmpty(" bob ") = true
  1. public static boolean isBlank(String str)
    Determine whether a string is empty or 0 in length or composed of whitespace
    Here is an example:
StringUtils.isBlank (null) =  trueStringUtils.isBlank ("") =  trueStringUtils.isBlank (" ") =  trueStringUtils.isBlank ("        ") =  trueStringUtils.isBlank ("- t / N / F / R") = true // for tab, line feed, page feed and carriage return StringUtils.isBlank () // all are recognized as white space StringUtils.isBlank ("\b") = false    //"- B" is the word boundary character StringUtils.isBlank ("bob") =  falseStringUtils.isBlank (" bob ") = false
  1. public static boolean isNotBlank(String str)
    Judge whether a string is not empty, length is not 0, and is not composed of 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

Objectutils provides two common methods for judging empty objectsisEmptyandisBlank

Whether isempty (string STR) is empty and the space character is false

Isnotempty (string STR) is not empty, and the space character is true

Whether isblank (string STR) is empty and the space character is true

Isnotblank (string STR) is not empty, space character is false

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]