当前位置:网站首页>isNotBlank与isNotEmpty
isNotBlank与isNotEmpty
2022-08-03 17:01:00 【欧菲斯集团】
isNotBlank与isNotEmpty
经常使用org.apache.commons.lang3.StringUtils中的isNotEmpty()和isNotBlank()方法进行判空。
- isNotEmpty()
public static void test1(String[] args) {
// isNotEmpty==判断某字符串是否非空
System.out.println(StringUtils.isNotEmpty(null)); // = false;
System.out.println(StringUtils.isNotEmpty("")); // false;
System.out.println(StringUtils.isNotEmpty(" "));// true;
System.out.println(StringUtils.isNotEmpty("bob")); // true;
}
- isNotBlank()
public static void test2(String[] args) {
// isNotBlank:判断某字符串是否不为空且长度不为0且不由空白符(whitespace)构成,
System.err.println(StringUtils.isNotBlank(null)); // false
System.err.println(StringUtils.isNotBlank("")); // false
System.err.println(StringUtils.isNotBlank(" ")); // false
System.err.println(StringUtils.isNotBlank("\t \n \f \r")); // false
}
由上面可以看出isNotEmpty()方法会对空字符串进行判为非空,而isNotBlank()方法会将空字符串判为空,还会把回车、换行等特殊字符进行判空。
- StringUtils中文api文档中介绍:
isNotEmpty()
isNotBlank()
isNotEmpty()和isNotBlank()提到了isEmpty()和isBlank()
isEmpty()
isBlank()
isNotEmpty等价于 a != null && a.length > 0
isNotBlank 等价于 a != null && a.length > 0 && str.trim().length > 0
日常使用isNotBlank()可以解决大多数问题,需要对" "进行判断处理时,使用isNotEmpty()
边栏推荐
- Looking at the ecological potential of Hongmeng OS from the evolution of MatePad Pro
- C专家编程 第1章 C:穿越时空的迷雾 1.9 阅读ANSI C标准,寻找乐趣和裨益
- 使用uniapp 封装一个request 请求
- JS 字符串转 GBK 编码超精简实现
- vant自动上传图片/文件
- leetcode:187. 重复的DNA序列
- FinClip | July 2022 Product Highlights
- 论文解读(JKnet)《Representation Learning on Graphs with Jumping Knowledge Networks》
- 附录A 程序员工作面试的秘密
- 数字资产的价值激发:NFT 质押
猜你喜欢
随机推荐
FinClip | July 2022 Product Highlights
security加密解密
C专家编程 第2章 这不是Bug,而是语言特性 2.1 这关语言特性何事,在Fortran里这就是Bug呀
C专家编程 第1章 C:穿越时空的迷雾 1.8 ANSI C标准的结构
组件通信-父传子组件通信
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
Adobe是什么?
请问下这个hologres维表是被缓存了么?怎么直接Finished了
为何微博又双叒叕崩溃了?
超分重建数据集
【LeetCode】899. 有序队列
LeetCode·72.编辑距离·动态规划
ArkUI如何适配横竖屏
Web3的开源为何会如此受到人们喜爱?
C专家编程 第3章 分析C语言的声明 3.3 优先级规则
EasyExcel实现动态列解析和存表
【GAMES101】作业6 加速结构
Detailed explanation of setting HiSilicon MMZ memory and OS memory
C语言01、数据类型、变量常量、字符串、转义字符、注释
一个域名对应多个IP地址









