I have a pre-populated array list. And I have multiple threads which will remove elements from the array list. Each thread calls the remove method below and removes one item
You can have 2 diffent problems with lists :
1) If you do a modification within an iteration even though in a mono thread environment, you will have ConcurrentModificationException like in this following example :
List list = new ArrayList();
for (int i=0;i<5;i++)
list.add("Hello "+i);
for(String msg:list)
list.remove(msg);
So, to avoid this problem, you can do :
for(int i=list.size()-1;i>=0;i--)
list.remove(i);
2)The second problem could be multi threading environment. As mentioned above, you can use synchronized(list) to avoid exceptions.