Cannot remove hashset in java -
this question has answer here:
i got problem hashset, cannot remove hashset, , here code
//take stopword list file public void stopwordlist(){ openfile("d:/thesiswork/perlengkapan/stopword.txt"); while(x.hasnext()){ string = x.nextline(); = a.tolowercase(); stopwords.add(a); } } //the method remove stopword public void stopwordremoval(){ stopwordlist(); //if word in streams set equal stopword, should removed for(string word:streams){ for(string sw:stopwords){ if(word.equals(sw)){ streams.remove(word); } } }
but, gives me exception, says :
exception in thread "main" java.util.concurentmodificationexception
, me? :)
you performing concurrent modification - iterating on collection , modifiying not iterator, should transform code this:
for (iterator<string> = streams.iterator(); it.hasnext();) { string word = it.next(); (string sw : stopwords) { if (word.equals(sw)) { it.remove(); break; } } }
Comments
Post a Comment