在 Java 6 中的 1 个语句中组合检查数组是否为 null
值或数组内容是否为 null
的最佳方法是什么:
if ((myArray[0] != null) || (myArray[1] != null) || (myArray!= null)) {
...
}
最佳答案
要让它检查任何值,我会使用 allMatch
。首先检查 array != null 也很重要,否则如果是的话,你会得到一个异常。
if (array == null || Arrays.stream(array).allMatch(Objects::isNull))
Note that this won't work with java prior to version 8, OP edited his requirements after I posted the answer
关于java - 如何检查数组是否为空或数组内容是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50741800/