当前位置:网站首页>Usage differences between isempty and isblank
Usage differences between isempty and isblank
2022-06-28 02:46:00 【An eagle 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
边栏推荐
- SQL报了一个不常见的错误,让新来的实习生懵了
- [2D code image correction and enhancement] simulation of 2D code image correction and enhancement processing based on MATLAB
- 【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
- MySQL optimization tips
- Win11不能拖拽图片到任务栏软件上快速打开怎么办
- 【历史上的今天】6 月 1 日:Napster 成立;MS-DOS 原作者出生;谷歌出售 Google SketchUp
- 在线JSON转PlainText工具
- Redis~Geospatial(地理空间)、Hyperloglog(基数统计)
- SQL injection bypass (IV)
- KVM related
猜你喜欢
Low code solution - a low code solution for digital after-sales service covering the whole process of work order, maintenance and Finance
Desai wisdom number - histogram (column folding mixed graph): ratio of rental price to rental income in the graduation quarter of 2021
榜单首发——前装搭载率站上10%大关,数字钥匙方案供应商TOP10
[today in history] May 29: the pioneer of sharing software was born; Chromebox launched; VoodooPC founder was born
How to systematically learn LabVIEW?
ScheduledThreadPoolExecutor源码解读(二)
【云原生】-Docker安装部署分布式数据库 OceanBase
High reliability application knowledge map of Architecture -- the path of architecture evolution
math_(函数&数列)极限的含义&误区和符号梳理/邻域&去心邻域&邻域半径
【历史上的今天】6 月 3 日:微软推出必应搜索引擎;Larry Roberts 启动阿帕网;Visual Basic 之父出生
随机推荐
【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线
【模糊神经网络】基于matlab的模糊神经网络仿真
A low-cost method to increase private domain traffic with simple maintenance
Prometheus 2.27.0 new features
[block coding] simulation of image block coding based on MATLAB
Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法
KVM related
LeetCode - Easy - 197
CRF+BiLSTM代码分步骤解读
如何系统学习LabVIEW?
LeetCode - Easy - 197
LiveData 面试题库、解答---LiveData 面试 7 连问~
[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes
[today in history] May 29: the pioneer of sharing software was born; Chromebox launched; VoodooPC founder was born
Prometheus 2.27.0 新特性
贪吃蛇 C语言
畢業總結
ROS+Gazebo中红绿黄交通灯如何实现?
云原生(三十) | Kubernetes篇之应用商店-Helm
「大道智创」获千万级preA+轮融资,推出科技消费机器人