String类型
1.StringUtils(Apache Commons Lang库中的一个类),该工具类是用于操作Java.lang.String类的。
StringUtils.isEmpty(str): return str == null || str.length() == 0
StringUtils.isBlank(str): return str == null || str.length() == 0 || str为空白
- 非空判断相对应的则是StringUtils.isNotEmpty(str) 和 StringUtils.isNotBlank(str)
2.String类自己的方法
str.isEmpty():只判断字符串长度是不是为0,str为null时,会报空指针异常
String类判空的两种方法:StringUtils.isEmpty(str)
str==null || str.isEmpty()
集合类型
1.CollectionUtils,该工具类用于操作List、Map集合类
CollectionUtils.isEmpty(coll):return coll == null || coll.isEmpty()
- 非空判断CollectionUtils.isNotEmpty(coll)
2.集合类自己的方法
coll.isEmpty():只判断是不是空集合,coll为null时,会报空指针异常
集合判空的两种方式:CollectionUtils.isEmpty(coll)
coll == null || coll.isEmpty()