【发布时间】:2017-11-14 11:19:38
【问题描述】:
在下面的代码中,我想在第一个“for 循环”中从 ArrayList 中删除为 null 或 arraylist 大小为零的项目。运行第一个循环后,我又有了第二个循环。在第二个循环中,我测试了它是否包含任何为空或项目大小为零的项目。虽然我在第一个循环中擦除,但 ArrayList BS 包含已从列表中删除的项目。
ArrayList<ArrayList<Record>> BS = new ArrayList<>();
.
.// some codes
.
for (int j = 0; j < BS.size(); j++) {
if(BS.get(j) == null || BS.get(j).size() == 0){
BS.remove(j);
}
}
for (int j = 0; j < BS.size(); j++) {
if(BS.get(j) == null || BS.get(j).size() == 0){
System.out.println("Again, fall into if condition");
}
}
【问题讨论】: