As the others said, you use object.equals(otherObject)
to compare objects in Java.
But your approach is completely wrong.
Try instead
Set stopWords = new HashSet(Arrays.asList("s", "t", "am",
"is", "are", "was", "were",
"has", "have", "been",
"will", "be", ...));
and then
private void refineWords() {
words.removeAll(stopWords);
}
and you should be done.
Further, note that with your current code you will get a ConcurrentModificationException
because you try to change the collection while you're iterating over it.
So if you can't use the abovewords.removeAll(stopWords)
, then you must instead use the much more verbose Iterator.remove()
method:
private void refineWords() {
for (Iterator<String> wordsIterator = words.iterator(); wordsIterator.hasNext(); ) {
String word = wordsIterator.next();
if (stopWords.contains(word)) {
wordsIterator.remove();
}
}
}