java判断字符串是否为空

String str = xxx;

1、判断一个字符串是否为空,首先就要确保他不是null,然后再判断他的长度。

if(str != null && str.length() != 0) { }

2、isEmpty完全等同于string.length()==0

if(string ==null || string.isEmpty()) { }

3、通过  "".equals(str)  比较的方法判断是否为空串

4、通过StringUtils 方法来判断

① StringUtils.isNotEmpty(str)等价于 str != null && str.length > 0。
② StringUtils.isNotBlank(str) 等价于 str != null && str.length > 0 && str.trim().length > 0
原文地址:https://www.cnblogs.com/wyzl/p/13731704.html