我在这里尝试做的是获取链表并循环检查匹配的数据并将其从链表中删除。在下图中,大小为4,但它只循环2次而不是4次。什么可以导致循环只循环两次而不是4次?
从系统日志开始,链表的大小为4,但删除(索引)后为2,假设为空。
public static void filteringClear(LinkedList<FileMeta> fileMetaList, String userName, String batchNo) {
System.out.println("LL size - " +fileMetaList.size());
for (int i = 0; i < fileMetaList.size(); i++) {
System.out.println("get owner name - " +fileMetaList.get(i).getOwenerId() + " and " +userName);
// check the username of data
if (fileMetaList.get(i).getOwenerId().equals(userName) || fileMetaList.get(i).getOwenerId().contains(userName)) {
System.out.println("get file batch - " +fileMetaList.get(i).filebatch + " and - " +batchNo);
// check the batch number of data
if (fileMetaList.get(i).filebatch == batchNo || fileMetaList.get(i).filebatch.contains(batchNo)) {
fileMetaList.remove(fileMetaList.get(i));
System.out.println("Clear file batch - " + fileMetaList.get(i).filebatch);
}
}
}
System.out.println("LL size - " +fileMetaList.size());
}