Search code examples
javaarraylistloopsstack-overflow

StackOverflowError when removing ArrayList object


I have an arraylist of classes and when I perform the below function I get a StackOverflowError thrown sometimes and I'm not 100% sure why, surely the if statement should rule this out? It only contains <500 elements as well and no other threads fiddle with "toCheck".

if(toCheck.contains(currentConsideration)){
    toCheck.remove(currentConsideration);
}

Any help would be much appreciated!


Solution

  • This could be because of you are trying to remove a object which you are trying to find it in the list... ConcurrentModificationException.

    If you try to debug. At what time you will get tis error

    post the solution if you find any