I had to remove few items from a list. I was removing one by one with the List.remove(object). Then got this exception. I was looking for a quick solution. Without being bothered about concurrency. I just made another list of elements which has to be removed from my main list. And finally called the List.removeAll(Collection). It worked nice.
Code is like this.
List myMainList;iterate over myMainList
if(certain conditions)
myMainList.removeAll(elementsToBeRemoved);elementsToBeReoved.add(theElement);
No comments:
Post a Comment