In my programm I have a List of Strings and a List of integer values which should be deleted from the first list. Think of somehing like this:
ArrayList<String> items = new ArrayList<String>();
items.add("A"); items.add("B"); items.add("C");
ArrayList<Integer> del = new ArrayList<Integer>();
del.add(1); del.add(2);
Of course I can loop throught the list with this code and delete the items:
for (int i = 0; i < del.size(); i++)
{
items.remove(del.get(i));
}
But here is the problem. After the first element is deleted the index is shifted so I delete the wrong items. Is there a graceful solution for this?
ArrayList<Integer> del = new ArrayList<String>();ArrayList<Integer> del = new ArrayList<String>();<-- this will not compile