当前位置:网站首页>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 .
边栏推荐
- KF UD分解之UD分解基础篇【1】
- Unity scene jump and exit
- 3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
- 闇の連鎖(LCA+树上差分)
- Solution to the problem of automatic login in Yanshan University Campus Network
- [offer18] delete the node of the linked list
- (core focus of software engineering review) Chapter V detailed design exercises
- (3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
- Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
猜你喜欢

Fabrication of fairygui simple Backpack

idea中好用的快捷键

Unity3d makes the registration login interface and realizes the scene jump

Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance

2021.11.10 compilation examination
![[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once](/img/f7/23ffc81ec8e9161c15d863c1a67916.png)
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once

Unity scene jump and exit

Expected value (EV)
![[算法] 剑指offer2 golang 面试题10:和为k的子数组](/img/63/7422489d09a64ec9f0e79378761bf1.png)
[算法] 剑指offer2 golang 面试题10:和为k的子数组

FairyGUI增益BUFF數值改變的顯示
随机推荐
【干货】提升RTK模糊度固定率的建议之周跳探测
Combination of fairygui check box and progress bar
Special palindromes of daily practice of Blue Bridge Cup
(课设第一套)1-4 消息传递接口 (100 分)(模拟:线程)
FairyGUI简单背包的制作
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
(the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
[算法] 剑指offer2 golang 面试题1:整数除法
PRIDE-PPPAR源码解析
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
Acwing-116 pilot brother
[offer9]用两个栈实现队列
RTKLIB: demo5 b34f.1 vs b33
How to improve the deletion speed of sequential class containers?
基于rtklib源码进行片上移植的思路分享
Unity场景跳转及退出
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
MySQL shutdown is slow
Lean product development - Lean Software Development & lean product development
Knowledge system of digital IT practitioners | software development methods -- agile