当前位置:网站首页>Usage differences between isempty and isblank
Usage differences between isempty and isblank
2022-07-05 10:12:00 【A bird carved in the desert】
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
边栏推荐
- 字节跳动面试官:一张图片占据的内存大小是如何计算
- Cross process communication Aidl
- 双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
- Generics, generic defects and application scenarios that 90% of people don't understand
- Cerebral Cortex:有向脑连接识别帕金森病中广泛存在的功能网络异常
- The Alipay in place function can't be found, and the Alipay in place function is offline
- Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
- Fluent generates icon prompt logo widget
- How to get the STW (pause) time of GC (garbage collector)?
- [app packaging error] to proceed, either fix the issues identified by lint, or modify your build script as follow
猜你喜欢
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
Wechat applet - simple diet recommendation (3)
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB
硬核,你见过机器人玩“密室逃脱”吗?(附代码)
Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
能源势动:电力行业的碳中和该如何实现?
最全是一次I2C总结
程序员搞开源,读什么书最合适?
历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
基于单片机步进电机控制器设计(正转反转指示灯挡位)
随机推荐
Jupiter notebook shortcut key
.Net之延迟队列
Zblogphp breadcrumb navigation code
[app packaging error] to proceed, either fix the issues identified by lint, or modify your build script as follow
Charm of code language
如何获取GC(垃圾回收器)的STW(暂停)时间?
Those who are good at using soldiers, hide in the invisible, and explain the best promotional value works in depth in 90 minutes
C#函数返回多个值方法
Tdengine already supports the industrial Intel edge insight package
Baidu app's continuous integration practice based on pipeline as code
【系统设计】指标监控和告警系统
历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
The essence of persuasion is to remove obstacles
Understand the window query function of tdengine in one article
Comparison of batch merge between Oracle and MySQL
StaticLayout的使用详解
[system design] index monitoring and alarm system
善用兵者,藏于无形,90 分钟深度讲解最佳推广价值作品
Swift saves an array of class objects with userdefaults and nssecurecoding
Advanced opencv:bgr pixel intensity map