java中数组的length长度为初始化时指定的长度, 和集合不一样
import org.apache.commons.lang3.StringUtils;
/**
* @description 数组简易工具类
* @Date 2020/6/16 17:59
*/
public class ArrayUtils {
public static boolean isAllEmpty(String[] arr) {
if (arr == null || arr.length == 0) {
return false;
}
boolean isAllEmpty = true;
for (String str : arr) {
if (StringUtils.isNotBlank(str)) {
isAllEmpty = false;
break;
}
}
return isAllEmpty;
}
// 简单测试
public static void main(String[] args) {
System.out.println(isAllEmpty(new String[2]));
System.out.println(isAllEmpty(new String[3]));
String[] strings = new String[3];
strings[0] = "";
System.out.println(isAllEmpty(strings));
String[] strings2 = new String[3];
strings2[2] = "1";
System.out.println(isAllEmpty(strings2));
}
}