What Im trying to do here is get the linked list and loop through check the matching data and remove it from the linked list. In the pic below, the size was 4 but it only loop 2 times instead of 4 times. What can cause the loop only loop twice instead of 4 times?
As from the log of the system, the size of the linked list is 4, but after the remove(index) is 2 which suppose to be empty.
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());
}