I have two arraylist fileWordList and stopWordList. I want to compare fileWordList to stopWordList and delete any same words from fileWordList. My codes are as below:
ArrayList<String> fileWordList = new ArrayList<String>();
ArrayList<String> stopWordList = new ArrayList<String>();
for (Iterator<String> i = fileWordList.iterator(); i.hasNext(); ) {
for(Iterator<String> j = stopWordList.iterator(); j.hasNext();){
if (j.next() == i.next()){
i.remove();
}
}
}
The error was caused by: java.util.NoSuchElementException. How to solve this? What is wrong with the code?
Setinstead ofListfor large collections. Then you could do:fileWordSet.removeAll(stopWordSet). This would also take care of multiple occurences.