当前位置:网站首页>The usage difference between isempty and isblank is so different that so many people can't answer it
The usage difference between isempty and isblank is so different that so many people can't answer it
2022-06-24 22:35:00 【Final code lifetime】
Click on “ End of life ”, Focus on , Official account
Daily technical dry goods , First time delivery !
Maybe you don't know either , Maybe you except isEmpty/isNotEmpty/isNotBlank/isBlank Outside , I don't know there are isAnyEmpty/isNoneEmpty/isAnyBlank/isNoneBlank The existence of , come on , Let's explore org.apache.commons.lang3.StringUtils; This tool class .
isEmpty series
StringUtils.isEmpty()
Is it empty . You can see " " Spaces will bypass this empty judgment , Because it's a space , Not strictly null , It can lead to isEmpty(" ")=false
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty(“bob”) = false
StringUtils.isEmpty(" bob ") = false
/**
*
* <p>NOTE: This method changed in Lang version 2.0.
* It no longer trims the CharSequence.
* That functionality is available in isBlank().</p>
*
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is empty or null
* @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
*/
public static boolean isEmpty(final CharSequence cs) {
return cs == null || cs.length() == 0;
}
StringUtils.isNotEmpty()
Equivalent to not empty , = !isEmpty()
public static boolean isNotEmpty(final CharSequence cs) {
return !isEmpty(cs);
}
StringUtils.isAnyEmpty()
Whether one is empty , Only one is empty , for true.
StringUtils.isAnyEmpty(null) = true
StringUtils.isAnyEmpty(null, “foo”) = true
StringUtils.isAnyEmpty("", “bar”) = true
StringUtils.isAnyEmpty(“bob”, “”) = true
StringUtils.isAnyEmpty(" bob ", null) = true
StringUtils.isAnyEmpty(" ", “bar”) = false
StringUtils.isAnyEmpty(“foo”, “bar”) = false
/**
* @param css the CharSequences to check, may be null or empty
* @return {@code true} if any of the CharSequences are empty or null
* @since 3.2
*/
public static boolean isAnyEmpty(final CharSequence... css) {
if (ArrayUtils.isEmpty(css)) {
return true;
}
for (final CharSequence cs : css){
if (isEmpty(cs)) {
return true;
}
}
return false;
}
StringUtils.isNoneEmpty()
amount to !isAnyEmpty(css) , All values must be non null to return true
/**
* <p>Checks if none of the CharSequences are empty ("") or null.</p>
*
* <pre>
* StringUtils.isNoneEmpty(null) = false
* StringUtils.isNoneEmpty(null, "foo") = false
* StringUtils.isNoneEmpty("", "bar") = false
* StringUtils.isNoneEmpty("bob", "") = false
* StringUtils.isNoneEmpty(" bob ", null) = false
* StringUtils.isNoneEmpty(" ", "bar") = true
* StringUtils.isNoneEmpty("foo", "bar") = true
* </pre>
*
* @param css the CharSequences to check, may be null or empty
* @return {@code true} if none of the CharSequences are empty or null
* @since 3.2
*/
public static boolean isNoneEmpty(final CharSequence... css) {
isBank series
StringUtils.isBlank()
Whether it is vacuum value ( Space or null value )
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank(“bob”) = false
StringUtils.isBlank(" bob ") = false
/**
* <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is null, empty or whitespace
* @since 2.0
* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
*/
public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (Character.isWhitespace(cs.charAt(i)) == false) {
return false;
}
}
return true;
}
StringUtils.isNotBlank()
Is it really not empty , Not a space or a null value , amount to !isBlank();
public static boolean isNotBlank(final CharSequence cs) {
return !isBlank(cs);
}
StringUtils.isAnyBlank()
Whether any vacuum value is included ( Contains spaces or null values )
StringUtils.isAnyBlank(null) = true
StringUtils.isAnyBlank(null, “foo”) = true
StringUtils.isAnyBlank(null, null) = true
StringUtils.isAnyBlank("", “bar”) = true
StringUtils.isAnyBlank(“bob”, “”) = true
StringUtils.isAnyBlank(" bob ", null) = true
StringUtils.isAnyBlank(" ", “bar”) = true
StringUtils.isAnyBlank(“foo”, “bar”) = false
/**
* <p>Checks if any one of the CharSequences are blank ("") or null and not whitespace only..</p>
* @param css the CharSequences to check, may be null or empty
* @return {@code true} if any of the CharSequences are blank or null or whitespace only
* @since 3.2
*/
public static boolean isAnyBlank(final CharSequence... css) {
if (ArrayUtils.isEmpty(css)) {
return true;
}
for (final CharSequence cs : css){
if (isBlank(cs)) {
return true;
}
}
return false;
}
StringUtils.isNoneBlank()
Whether none of them contain null values or spaces
StringUtils.isNoneBlank(null) = false
StringUtils.isNoneBlank(null, “foo”) = false
StringUtils.isNoneBlank(null, null) = false
StringUtils.isNoneBlank("", “bar”) = false
StringUtils.isNoneBlank(“bob”, “”) = false
StringUtils.isNoneBlank(" bob ", null) = false
StringUtils.isNoneBlank(" ", “bar”) = false
StringUtils.isNoneBlank(“foo”, “bar”) = true
/**
* <p>Checks if none of the CharSequences are blank ("") or null and whitespace only..</p>
* @param css the CharSequences to check, may be null or empty
* @return {@code true} if none of the CharSequences are blank or null or whitespace only
* @since 3.2
*/
public static boolean isNoneBlank(final CharSequence... css) {
return !isAnyBlank(css);
}
StringUtils Other methods
You can refer to the official documents , There's a detailed description , Some methods are still very easy to use .
https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html


PS: Prevent missing this article , You can like it , It's easy to browse and search
边栏推荐
- 04A中断的配置
- 零代码即可将数据可视化应用到企业管理中
- Firewall working principle and detailed conversation table
- How to extract dates from web pages?
- In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience
- New features of go1.18: efficient replication, new clone API for strings and bytes standard library
- NIO多路复用之Selector的使用
- Envoy obtain the real IP address of the client
- Problèmes de concurrence dans l'allocation de mémoire en tas
- Docker installs MySQL 8.0. Detailed steps
猜你喜欢

DAO 中常见的投票治理方式

Information update on automatic control principle

重磅!法大大上榜“专精特新”企业

零代码即可将数据可视化应用到企业管理中

Can AI chat robots replace manual customer service?

How does flutter use the online transcoding tool to convert JSON to model
Relationnet++: a representation of fusion of multiple detection targets based on transformer | neurips 2020

KT6368A蓝牙芯片的主从机之前透传功能说明,2.4G跳频自动连接

What aspects should we start with in the feasibility analysis of dry goods?

Future development of education industry of e-commerce Express
随机推荐
Development of live broadcast software app, and automatic left-right sliding rotation chart advertising
磁盤的結構
虚拟人的产业发展现状
系统测试主要步骤
Interrupt, interrupted, isinterrupted differences
socket(2)
Huada 04A operating mode / low power consumption mode
Valueerror: cannot take a larger sample than population when 'replace=false‘
如何提取网页中的日期?
img2pdf
Can AI chat robots replace manual customer service?
Heartless sword Chinese English bilingual poem 003 The sea of books
第二批入围企业公示!年度TOP100智能网联供应商评选
How does flutter use the online transcoding tool to convert JSON to model
KT6368A蓝牙双模透传芯片软件版本选型说明
解决dataframe报错ValueError: Cannot take a larger sample than population when ‘replace=False‘
NIO多路复用之Selector的使用
Why can some programmers get good offers with average ability?
[Software Engineering] key points at the end of the period
Certificate photo processing