【发布时间】:2015-04-15 16:45:31
【问题描述】:
这是我的代码:
for (int i = 0; i < myarraylist.size(); i++) {
for (int j = 0; j < stopwords.size(); j++) {
if (stopwords.get(j).equals(myarraylist.get(i))) {
myarraylist.remove(i);
id.remove(i);
i--; // to look at the same index again!
}
}
}
我有问题..删除元素后,所有索引总是改变,上面的循环太乱了。
为了说明: 我有 54 条数据,但在删除元素后,上面的循环变得混乱。所以只有 50 条数据被检查。
还有其他方法或修复我的代码以按索引删除多个元素?? 元素索引对我来说非常重要,要删除另一个具有相同索引的数组列表。
【问题讨论】:
-
使用
Iterator在循环时删除元素。
标签: java android arraylist stop-words