当前位置:网站首页>Usage differences between isempty and isblank
Usage differences between isempty and isblank
2022-07-06 12:51:00 【Demon Lord】
First , Both methods use tool classes StringUtils The method inside , Are used to determine whether the string is empty
And this tool class is everywhere , Recommended Apache Of Not bound by the frame , The method is also complete
1)isEmpty
Determine whether the string is an empty string , As long as there is an arbitrary character ( Include white space characters ) It's not empty .
Look at isEmpty Source code of the method :
public static boolean isEmpty(CharSequence cs) {
return cs == null || cs.length() == 0;
}
This method only judges whether it is for null Or the length is 0.
signify , If user input " " And so on , This method will not pass , The result is not empty .
If you want to verify, enter the following :
Input content | Is it empty |
---|---|
" " | no |
"" | yes |
"Java Technology stack " | no |
2、isBlank
Determine whether the string is an empty string , All white space characters are also empty .
Look at isBlank Source code of the method :
public static boolean isBlank(CharSequence cs) {
int strLen = length(cs);
if (strLen == 0) {
return true;
} else {
for(int i = 0; i < strLen; ++i) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
}
The first 7 That's ok , As long as one character is not a blank character, it returns false, in other words , If all are white space characters, it returns true, That is, all white space characters are empty .
If you want to verify, enter the following :
Input content | Is it empty |
---|---|
" " | yes |
"" | yes |
"Java Technology stack " | no |
Now , If user input " " And so on , This method also returns null , This is also what we expect in most business scenarios .
边栏推荐
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- JUC forkjoin and completable future
- Itext 7 生成PDF总结
- [算法] 剑指offer2 golang 面试题1:整数除法
- Idea problem record
- First use of dosbox
- FairyGUI复选框与进度条的组合使用
- rtklib单点定位spp使用抗差估计遇到的问题及解决
- FGUI工程打包发布&导入Unity&将UI显示出来的方式
- Unity3D制作注册登录界面,并实现场景跳转
猜你喜欢
随机推荐
基于rtklib源码进行片上移植的思路分享
使用rtknavi进行RT-PPP测试
最短Hamilton路径 (状压DP)
[offer78] merge multiple ordered linked lists
KF UD分解之UD分解基础篇【1】
Prove the time complexity of heap sorting
VLSM variable length subnet mask partition tips
(1) Introduction Guide to R language - the first step of data analysis
[offer29] sorted circular linked list
GNSS定位精度指标计算
Special palindromes of daily practice of Blue Bridge Cup
idea中好用的快捷键
FairyGUI按钮动效的混用
[algorithm] sword finger offer2 golang interview question 2: binary addition
Teach you to release a DeNO module hand in hand
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
Halcon knowledge: gray_ Tophat transform and bottom cap transform
Fairygui loop list