Java method of judging empty space

Java method of judging empty space

1. The data structure judges empty (map, list, set)
CollectionUtils.isEmpty() is empty
CollectionUtils.isNotEmpty() is not empty

2. The object is judged as empty
Objects.isNull() is empty
Objects.nonNull() is not empty

3. The string is judged as empty
StringUtils.isNotEmpty() is not empty
StringUtils.isEmpty() is empty
StringUtils.isNotBlank() is not empty
StringUtils.isBlank() is empty

4. The difference between isBlank() and isEmpty()
(1), public static  boolean  isEmpty(String str)
judges whether a string is empty, and the standard for being empty is str==null or str.length()==
0 This is an example:
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false //Note that spaces are not empty in StringUtils
StringUtils.isEmpty(" ") = false
StringUtils .isEmpty("bob") = false
StringUtils.isEmpty("bob") = false

(2). public static boolean isBlank(String str)
determines whether a string is empty or has a length of 0 or consists of whitespace characters.
The following 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, newlines, form feeds Both StringUtils.isBlank() and the carriage return character are recognized as blank characters
StringUtils.isBlank("\b") = false //"\b" is a word boundary character
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false

Guess you like

Origin blog.csdn.net/weixin_49934658/article/details/130205523