如果给定索引处的子列表不为null,则返回true,否则返回false



我的计算得到了AssertionError。

public boolean subListNullCheck (ArrayList<ArrayList<Integer>> list, int j) {
if(list == null || list.isEmpty() || list.get(0).isEmpty() ) {
return false;

} if(list.contains(j)) {
return true;
}
return false;
}
如果list包含值j,则list.contains(j)返回true,而不是如果索引j处的元素不为null。

你可以写:

public boolean subListNullCheck (ArrayList<ArrayList<Integer>> list, int j) {
if (list == null) {
return false;             
} else if (j >= 0 && list.size > j && list.get(j) != null) {
return true;
}
return false;
}

或者只是

public boolean subListNullCheck (ArrayList<ArrayList<Integer>> list, int j) {
return list != null && j >= 0 &&& list.size > j && list.get(j) != null;
}

最新更新