当前位置:网站首页>What's the difference between isempty and isblank? Half of the people can't answer it?
What's the difference between isempty and isblank? Half of the people can't answer it?
2022-06-29 16:28:00 【Program ape DD_】
author :Moshow Zheng Kai , source :blog.csdn.net/moshowgame/article/details/102914895
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;
}/**
*
* <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) {
return !isAnyEmpty(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
We have created a high-quality technical exchange group , With good people , I will be excellent myself , hurriedly Click Add group , Enjoy growing up together . in addition , If you want to change jobs recently , Years ago, I spent 2 A wave of large factory classics were collected in a week , Those who are ready to change jobs after the festival can Click here to get !
Recommended reading
StackOverflow 2022 Developer reports :PostgreSQL transcend MySQL !
Summary of high concurrency experience under 100 million level traffic !
blockbuster !VS Code 6 Monthly update :Spring Boot Major functional upgrades !
··································
Hello , I'm a procedural ape DD,10 Old driver developed in 、 Alibaba cloud MVP、 Tencent cloud TVP、 I have published books and started a business 、 State-owned enterprises 4 In the Internet 6 year . From ordinary developers to architects 、 Then to the partner . Come all the way , My deepest feeling is that I must keep learning and pay attention to the frontier . As long as you can hold on , Think more 、 Don't complain 、 Do it frequently , It's easy to overtake on a curve ! therefore , Don't ask me what I'm doing now, whether it's in time . If you are optimistic about one thing , It must be persistence to see hope , Instead of sticking to it when you see hope . believe me , Just stick to it , You must be better than now ! If you don't have any direction , You can pay attention to me first , Some cutting-edge information is often shared here , Help you accumulate the capital to overtake on the curve .
边栏推荐
- What is the strength of a software testing engineer who can get a salary increase twice a year?
- 按键精灵打怪学习-窗口绑定技能
- leetcode:139. Word splitting [DFS + memory]
- 「BUAA OO Unit 4 HW16」第四单元总结与课程回顾
- TLBB series of Tianlong Babu - online single use database modified to other sects
- 南京大学:新时代数字化人才培养方案探讨
- The understanding of industrial Internet is directly related to how we view it
- 事件相关电位ERP的皮层溯源分析
- 稳定币风险状况:USDT 和 USDC 安全吗?
- 连续10年霸榜第一?程序员「最常用」的编程语言是它?
猜你喜欢

同样是做测试,为什么别人年薪30W+?

MySQL foundation - transaction

真正的测试 =“半个产品+半个开发”?

STM32按键消抖——入门状态机思维
![leetcode:139. Word splitting [DFS + memory]](/img/6f/8936ed3579c6a6dc3d8d312b413aff.png)
leetcode:139. Word splitting [DFS + memory]

Metadata management Apache Atlas Compilation integration deployment and testing

UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology

Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具

都3年测试经验了,用例设计还不知道状态迁移法?

美国芯片再遭重击,Intel或将被台积电击败而沦落至全球第三
随机推荐
又拍云 Redis 的改进之路
天龙八部TLBB系列 - 网单用数据库修改为其他门派
南京大学:新时代数字化人才培养方案探讨
Which version of JVM is the fastest?
Apache atlas breakpoint view
Is it safe to open a compass account and speculate in stocks? How individuals open accounts for stock trading
Notice on organizing the declaration of Nanjing innovative products (the first batch) in 2022
基础 | 在物理引擎中画圆弧
Blue Bridge Cup 2015 CA provincial competition (filling the pit)
Sophon autocv: help AI industrial production and realize visual intelligent perception
Profil de risque de monnaie stable: l'usdt et l'USDC sont - ils sûrs?
What is the strength of a software testing engineer who can get a salary increase twice a year?
C language -- printf print base prefix
星环科技数据安全管理平台 Defensor重磅发布
SAAS服务都有哪些优势
[rust daily] rust 2021 stability
数学知识:求组合数 II—求组合数
有哪些顶级水平的中国程序员?
Mysql database Basics: introduction to data types
Summary of common MySQL statements and commands