空数组判断
开发代码为:
String originCountry2 = "";
String[] originCountries = originCountry2.split(",");
if(originCountries == null || originCountries.length > 1){
System.out.println("执行操作1..............");
}
else{
System.out.println("执行操作2..............");
}
经调试发现空数组永远不等于null,所以就导致走了错误的逻辑:
执行操作1…
正确代码:
String originCountry2 = "";
String[] originCountries = originCountry2.split(",");
if(originCountries.length != 1){
System.out.println("执行操作1..............");
}
else{
System.out.println("执行操作2..............");
}
执行结果:
执行操作2…