我想知道这段代码对于检查数组是否为空是否有效,或者我应该检查 null 吗?
if(arrayName={})
System.out.println("array empty");
else System.out.println("array not empty");
谢谢你!
我会考虑通过从此处添加 Apache Commons Lang 来使用 ArrayUtils.is 空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");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)