For循环不循环遍历所有索引

时间:2018-06-11 04:27:35

标签: java for-loop if-statement linked-list

我在这里尝试做的是获取链表并循环检查匹配的数据并将其从链表中删除。在下图中,大小为4,但它只循环2次而不是4次。什么可以导致循环只循环两次而不是4次?

enter image description here

从系统日志开始,链表的大小为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());
}

0 个答案:

没有答案