当前位置:网站首页>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 .
边栏推荐
- [leetcode19]删除链表中倒数第n个结点
- Knowledge system of digital IT practitioners | software development methods -- agile
- [Chongqing Guangdong education] Shandong University College Physics reference materials
- Mysql database index
- Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
- [offer9] implement queues with two stacks
- 2021.11.10 compilation examination
- PRIDE-PPPAR源码解析
- Get the position of the nth occurrence of the string
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
猜你喜欢

Easy to use shortcut keys in idea

Fairygui loop list

C programming exercise

MySQL shutdown is slow

Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)

Unity scene jump and exit

Liste des boucles de l'interface graphique de défaillance

idea中导包方法

FairyGUI人物状态弹窗

Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
随机推荐
Force buckle 1189 Maximum number of "balloons"
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
In 2020, the average salary of IT industry exceeded 170000, ranking first
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
Matlab读取GNSS 观测值o文件代码示例
Derivation of logistic regression theory
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
GPS高程拟合抗差中误差的求取代码实现
FairyGUI摇杆
2021.11.10汇编考试
Meanings and differences of PV, UV, IP, VV, CV
[offer18] delete the node of the linked list
SVN更新后不出现红色感叹号
Introduction to the daily practice column of the Blue Bridge Cup
Unity3D,阿里云服务器,平台配置
Teach you to release a DeNO module hand in hand
Devops' future: six trends in 2022 and beyond
Mysql database index
染色法判定二分图
idea问题记录