0

I am having some trouble implementing the iterator.remove() method correctly. I am trying to use the method to remove certain strings from an ArrayList of strings, but every time I try using an iterator (and the iterator.remove() method), I get an error titled "Check For Comodification". I am posting my code below for reference. Appreciate the help!

        Iterator<String> iter= myWords.iterator();
        while(iter.hasNext()){  
            String current= iter.next();
            for(int i=0;i<current.length();i++){
                if(current.charAt(i)==mostFrequentChar){
                    iter.remove();
                    break;
                }
            }
        }
sasankad
  • 3,543
  • 3
  • 24
  • 31
user2904796
  • 267
  • 1
  • 6
  • 19

1 Answers1

0

"Check For Comodification" usually means that something is already modifying the Collection at the same time while iterating over it. Check this out.