Operations on String
that are null
safe。也就是说在此包内对字符串的操作又做了层处理,所有的方法都不用担心会空指针异常。
isEmpty/isBlank()方法是检查字符串是否为空
区别
如果String str = " ";//串中有空格。
boolean res1 =StringUtils.isBlank(str);
boolean res2 =StringUtils.isEmpty(str);
结果:res1 =true,res2=false,
如果String str = null;
boolean res1 =StringUtils.isBlank(str);
boolean res2 =StringUtils.isEmpty(str);
结果:res1 =true,res2=true,
Trim/Strip 去掉首尾部空格
deleteWhitespace() 去掉字符串中的空格 如: StringUtils.deleteWhitespace("a d df")=addf
indexOf() 和J2SE的indexOf()的区别,前者传入null不会抛空指针异常