This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14328|Reply: 0

[Source] The isEmpty, isBlank, isNotEmpty, and isNotBlank methods in the Java tool class StringUtils

[Copy link]
Posted on 6/28/2019 3:55:23 PM | | |
1. Detailed explanation of the source code of the isEmpty method



Source code analysis: The above method shows that true is returned only when the string is not a null and non-empty string (""). isNotEmpty method is the opposite of isEmpty;

See the following official website example:


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


2. Detailed explanation of the source code of the isBlank method



Source code analysis: First, if the parameters passed in are null or empty strings, it will return true, and then use the Character.isWhitespace method to determine whether the characters are all blank characters (spaces, tab keys, line breaks), if so, return false, otherwise return true; isNotBlank method is the opposite of isBlank method;

Take a look at the example on the official website:


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


3. isAnyBlank source code

Source code analysis: First, whether the parameter array is empty, if it is null, it returns false, if the array is non-empty, it determines whether each string in the array is a blank character, and returns true if there is a blank character; isNoneBlank identifies that none of the elements in the array are whitespace, as opposed to isAnyBlank;

4. isAllBlank source code analysis


Source code analysis: First, determine whether the parameter array is empty, if it is true, otherwise it will return false if one of the elements in the array is non-whitespace.




Previous:Java file traversal
Next:Java encapsulation zip unzip method
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com