Hello I have 2 arraylists (aryList1 contains 1s and 0s indicating indices that need updating or removing; and aryList2 contains the items that are to be updated or removed). The 2 arylists' size ARE the same.
My update code
I found if I leave out the remove(i) line, the arraylist size after update increases by the number of items you are updating. Eg aryList2 original size is 3, after update becomes 5 if I update 2 items. Why is that? Once I add the remove(i) line the size becomes consistent.
As for the remove code, I found that it WILL prompt IndexOutOfBoundsException if I don't start removing from the first item. Suppose I have 3 items in aryList2. I want to remove 2nd and 3rd items (index 1 and 2 of aryList2). My remove code
IDEAL logic: original size is 3 i=0 prints index0 !=1 continue i=1 prints index1 ==1 remove(1) and prints size=2 i=2 prints index2 ==1 remove(2) and prints size=1
BUT when i=2 IndexOutOfBoundsException. I understand this exception prompts if index>=size which it is when i=2. So how to avoid this?