2 回答

TA贡献1818条经验 获得超7个赞
null与空不同。列表的大小为 1,这意味着有 1 个对象(即使它的所有属性都为 null)。如果要检查其所有属性是否为空,则可以获取每个属性并检查它是否为空。
您可以使用其他方法来确定属性是否为 not 的 null,然后只调用它。例如:
public class DomainClass1 {
String str1, str2;
public boolean isEmpty() {
if (this.str1 != null && this.str2 != null) {
return false;
} else {
return true;
}
}
}
现在调用它,如下所示:
for (int i = 0; i < domain.size(); i++) {
if (domain.get(i).isEmpty()) {
// all fields null
} else {
// not all are null
}
}

TA贡献1864条经验 获得超6个赞
domain.isEmpty()
它只是验证列表是空的,它不验证d的字段是空的,你可以在DomainClass1类中添加一个方法,就像这样
public class DomainClass1 {
private String test1;
private String test2;
private String test3;
private String test4;
...
public boolean isEmpty() {
if(test1 != null || test2 != null || test3 != null || test4 != null) {
return false;
}
return true;
}
}
那么你可以使用 d.isEmpty() 来替换 domain.isEmpty()
添加回答
举报