当前位置:网站首页>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()
边栏推荐
- Description of the functional scenario of "collective storage and general governance" in the data center
- 【无标题】
- 为何微博又双叒叕崩溃了?
- 浅谈Service Mesh对业务系统的价值
- 为什么我用了Redis之后,系统的性能却没有提升
- 数据中台“集存通用治”功能场景说明
- 被误解的 MVC 和被神化的 MVVM(一)
- J9数字虚拟论:元宇宙的潜力:一股推动社会进步的力量
- 高效的组织信息共享知识库是一种宝贵的资源
- C专家编程 第1章 C:穿越时空的迷雾 1.11 轻松一下---由编译器定义的Pragmas效果
猜你喜欢

11. Container With Most Water

#夏日挑战赛#【FFH】OpenHarmony设备开发基础(四)启动流程

基于DMS的数仓智能运维服务,知多少?

leetcode:187. 重复的DNA序列

protobuf 反射使用总结

面试突击71:GET 和 POST 有什么区别?

phoenix创建映射表和创建索引、删除索引

高效的组织信息共享知识库是一种宝贵的资源

leetcode:189. 轮转数组

使用deepstream消息发送功能的时候,检测框没有检测标签,No text labels of bboxes displayed with osd for deepstream-test5
随机推荐
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
Adobe是什么?
我想请问下,我们的数据库是在亚马逊,Dataworks 连不通,怎么办?
FinClip | July 2022 Product Highlights
C语言03、数组
广告电商系统开发之会员系统板块
纯纯粹粹纯纯粹粹
高效的组织信息共享知识库是一种宝贵的资源
How ArkUI adapter somehow the screen
C专家编程 第3章 分析C语言的声明 3.7 typedef struct foo{... foo;}的含义
通用型安全监测数据管理系统
Which thread pool does Async use?
MobileVIT实战:使用MobileVIT实现图像分类
Auto Scaling 弹性伸缩(运维释放人力)
超分重建数据集
沃尔沃:这是会“种草”的“安全感”!
Async的线程池使用的哪个?
PTA递归练习
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践