当前位置:网站首页>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 .
边栏推荐
- 挖财学堂证券开户安全嘛?
- 工具链赋能百家,地平线开启智能驾驶量产的“马太效应”
- 小程序在产业互联网有「大」作为
- Science: the interrelated causes and consequences of sleep in the brain
- [rust daily] rust 2021 stability
- 分片信息调哪个参数呢?用的是MySQLsource stream api,不是table api
- Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
- 一个简单但是能上分的特征标准化方法
- Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
- 数学知识:求组合数 II—求组合数
猜你喜欢
数学知识复习:第一型曲线积分
CV5200自组网远程WiFi模组,无人机无线图传应用,高清低时延方案
Alipay "security lock" was selected as an excellent case in the "child care program" of the ICT Institute: more than 330000 users have opened game protection
Mysql database Basics: introduction to data types
UWB精准定位方案,厘米级高精度技术应用,智能配对感应技术
贪婪的苹果计划提高iPhone14的价格,这将为中国手机提供机会
BOE: with the arrival of the peak season in the second half of the year, the promotion and the release of new products, the demand is expected to improve
把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...
DAP large screen theme development description
穩定幣風險狀况:USDT 和 USDC 安全嗎?
随机推荐
星环科技数据安全管理平台 Defensor重磅发布
天龙八部TLBB系列 - 网单用数据库修改为其他门派
有哪些顶级水平的中国程序员?
稳定币风险状况:USDT 和 USDC 安全吗?
自己实现一个ThreadLocal
Apache atlas breakpoint view
实战 | Change Detection And Batch Update
对于产业互联网的认识,直接关系着我们究竟会以怎样的心态来看待它
【第28天】给定一个字符串S,请你判断它是否为回文字符串 | 回文的判断
我想网上注册股票开户,如何操作?另外,手机开户安全么?
基础 | 在物理引擎中画圆弧
一个简单但是能上分的特征标准化方法
【Proteus仿真】数码管+4x4键盘矩阵按键简易计算器
MySQL基础——多表查询
又拍云 Redis 的改进之路
Science:大脑中睡眠的相互关联原因和结果
What is the strength of a software testing engineer who can get a salary increase twice a year?
代码大全读后感
STM32按键消抖——入门状态机思维
Profil de risque de monnaie stable: l'usdt et l'USDC sont - ils sûrs?