StringUtils.isNotEmpty(String str) 判断某字符串是否不为空,不为为空的标准是 str!=null 或 str.length()> 0
isNotEmpty(str)等价于 str != null && str.length > 0 isNotBlank(str) 等价于 str != null && str.length > 0 && str.trim().length > 0 同理 isEmpty 等价于 str == null || str.length == 0 isBlank 等价于 str == null || str.length == 0 || str.trim().length == 0
isNotEmpty将空格也作为参数,isNotBlank则排除空格参数
StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出NullPointerException,而是做了相应处理,例如,如果输入为null则返回也是null等)
-----------------------
StringUtils.isEmpty(String str) 判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0 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.isNotEmpty(String str) 等价于 !isEmpty(String str) StringUtils.isBlank(String str) 判断某字符串是否为空或长度为0或由空白符(whitespace) 构成 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 StringUtils.isBlank(String str) 等价于 !isBlank(String str)
浙公网安备 33010602011771号