<分区>
我想知道这段代码对于检查数组是否为空是否有效,还是应该检查 null?
if(arrayName={})
System.out.println("array empty");
else System.out.println("array not empty");
谢谢!
<分区>
我想知道这段代码对于检查数组是否为空是否有效,还是应该检查 null?
if(arrayName={})
System.out.println("array empty");
else System.out.println("array not empty");
谢谢!
最佳答案
我会考虑使用 ArrayUtils.is empty 通过从这里添加 Apache Commons Lang http://commons.apache.org/proper/commons-lang/download_lang.cgi
最大的优势是这将以一种干净且易于阅读的方式为您对数组进行空检查。
然后你可以这样做:
if (ArrayUtils.isEmpty(arrayName) {
System.out.printLn("Array empty");
} else {
System.out.printLn("Array not empty");
}
关于java - 如何检查空数组java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34847190/