当前位置:网站首页>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()
边栏推荐
- 【系统学习编程-编程入门-全民编程 视频教程】
- Which thread pool does Async use?
- protobuf 反射使用总结
- 组件通信--下拉菜单案例
- LeetCode·899.有序队列·最小表示法
- C专家编程 第3章 分析C语言的声明 3.6 typedef int x[10]和#define x int[10]的区别
- EasyExcel implements dynamic column parsing and table storage
- 怎么在opengauss中进行测试自己添加的新函数的性能(循环n次的运行时间)?
- C专家编程 第1章 C:穿越时空的迷雾 1.10 “安静的改变”究竟有多少安静
- 设置海思芯片MMZ内存、OS内存详解
猜你喜欢
[Unity Getting Started Plan] Basic Concepts (7) - Input Manager & Input Class
通用型安全监测数据管理系统
虹科分享 | 如何测试与验证复杂的FPGA设计(3)——硬件测试
EasyExcel implements dynamic column parsing and table storage
C# 构造函数如人之影子
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
工程仪器设备在线监测管理系统常见问题和注意事项
华为、联想、北汽等入选工信部“企业数字化转型和安全能力提升”首批实训基地
双指针/滑动窗口问题
TiKV & TiFlash accelerate complex business queries丨TiFlash application practice
随机推荐
使用Stream多年,collect还有这些“骚操作”?
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
C语言01、数据类型、变量常量、字符串、转义字符、注释
uniapp 去掉默认导航栏
Web3 安全风险令人生畏?应该如何应对?
Excuse me this hologres dimension table is cached?How to Finished
高效的组织信息共享知识库是一种宝贵的资源
并发高的情况下,试试用ThreadLocalRandom来生成随机数
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
阿里二面:没有 accept,能建立 TCP 连接吗?
leetcode-每日一题899. 有序队列(思维题)
C专家编程 第3章 分析C语言的声明 3.1 只有编译器才会喜欢的语法
论文解读(JKnet)《Representation Learning on Graphs with Jumping Knowledge Networks》
Web3的开源为何会如此受到人们喜爱?
中小微企业如何简单便捷、低成本实现数字化?360视觉云有妙招
[Unity Starter Plan] Making RubyAdventure01 - Player Creation & Movement
TypeScript的配置文件tsconfig.json
204. Count Primes
deepstresam的插件配置说明,通过配置osd,设置字体的背景为透明
leetcode:189. 轮转数组