关于StringUtils类中isEmpty与isBlank的学习笔记

StringUtils类中isEmpty与isBlank的区别

org.apache.commons.lang.StringUtils类提供了String的常用操作,最为常用的判空有如下两种isEmpty(String str)和isBlank(String str)。

StringUtils.isEmpty(String str)

判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0,等价于 !isEmpty(String str)。

System.out.println(StringUtils.isEmpty(null));        //true
System.out.println(StringUtils.isEmpty(""));          //true
System.out.println(StringUtils.isEmpty("   "));       //false
System.out.println(StringUtils.isEmpty("dd"));        //false
StringUtils.isBlank(String str)

判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0,等价于 !isBlank(String str)。

System.out.println(StringUtils.isBlank(null));        //true
System.out.println(StringUtils.isBlank(""));          //true
System.out.println(StringUtils.isBlank("   "));       //true
System.out.println(StringUtils.isBlank("dd"));        //false  

文章为备忘,不喜勿喷,欢迎提议,谢谢。
转载至 苏若年

猜你喜欢

转载自blog.csdn.net/u012838207/article/details/80406002
今日推荐