当前位置:网站首页>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 .
边栏推荐
- Halcon knowledge: gray_ Tophat transform and bottom cap transform
- Naive Bayesian theory derivation
- How to reduce the shutdown time of InnoDB database?
- Minio file download problem - inputstream:closed
- Unity scene jump and exit
- SVN更新后不出现红色感叹号
- idea中导包方法
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- 【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
- [leetcode19] delete the penultimate node in the linked list
猜你喜欢
Fabrication of fairygui simple Backpack
FairyGUI摇杆
[算法] 剑指offer2 golang 面试题10:和为k的子数组
dosbox第一次使用
FairyGUI循環列錶
Idea problem record
2021.11.10 compilation examination
Unity3d, Alibaba cloud server, platform configuration
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
使用rtknavi进行RT-PPP测试
随机推荐
PRIDE-PPPAR源码解析
1041 be unique (20 points (s)) (hash: find the first number that occurs once)
[899] ordered queue
Fairygui character status Popup
NovAtel 板卡OEM617D配置步骤记录
Minio file download problem - inputstream:closed
[算法] 剑指offer2 golang 面试题1:整数除法
Teach you to release a DeNO module hand in hand
rtklib单点定位spp使用抗差估计遇到的问题及解决
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
FairyGUI复选框与进度条的组合使用
Servlet
(the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
[Offer29] 排序的循环链表
Database course design: college educational administration management system (including code)
wsl常用命令
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
idea问题记录
MySQL error warning: a long semaphore wait