remove (int index) arraylist method removes the item at the specified position (index) in the list. After deleting the elements of the array, any subsequent elements are shifted to the left.
So if the arrailist contains {20,15,30,40}
I called the method: arraylist.remove (1)
then data 15 will be deleted, and 30 and 40 these two elements will be shifted by 1.
For this reason, you need to remove the higher arraylist index element first.
So, for your specific situation ... the code will be ..
ArrayList<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); list.add("F"); list.add("G"); list.add("H"); int i[] = {1,3,5}; for (int j = i.length-1; j >= 0; j--) { list.remove(i[j]); }
Avijit Karmakar Mar 06 '16 at 14:28 2016-03-06 14:28
source share