当前位置:网站首页>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 .
边栏推荐
- [Offer18]删除链表的节点
- Unity3D,阿里云服务器,平台配置
- [leetcode622] design circular queue
- Lean product development - Lean Software Development & lean product development
- Fairygui character status Popup
- FairyGUI循环列表
- FairyGUI按钮动效的混用
- [Chongqing Guangdong education] Shandong University College Physics reference materials
- MySQL error warning: a long semaphore wait
- Get the position of the nth occurrence of the string
猜你喜欢
随机推荐
[算法] 剑指offer2 golang 面试题2:二进制加法
Knowledge system of digital IT practitioners | software development methods -- agile
Fairygui joystick
[algorithm] sword finger offer2 golang interview question 2: binary addition
[algorithm] sword finger offer2 golang interview question 1: integer division
Agile development helps me
(课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
[leetcode15] sum of three numbers
基于rtklib源码进行片上移植的思路分享
[offer9] implement queues with two stacks
FairyGUI摇杆
1041 be unique (20 points (s)) (hash: find the first number that occurs once)
【RTKLIB 2.4.3 b34 】版本更新简介一
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
FairyGUI循环列表
[算法] 剑指offer2 golang 面试题7:数组中和为0的3个数字
第一人称视角的角色移动
Fairygui character status Popup
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
Fairygui loop list