I'm supposed to read through a file, add all the new words to an arraylist, and if the word is already in the list, increase a counter on how many times it has appeared. I read in the words just fine, but when it comes to adding them to the list, it seems to ignore the part where it checks whether the word is already in the list and adds multiples of the same word. What I've got:
Reading method:
public void read(String text) throws Exception{
File fileText = new File(text);
Scanner in = new Scanner(fileText);
while(in.hasNextLine()){
newWord = new Word(in.nextLine());
add(newWord.text);
}
}
Method for adding to arraylist
public void add(String text){
for(Word o: wordList){
if(wordList.contains(newWord.text){
newWord.increaseCount();
}else{
wordList.add(newWord);
}
}
Would really appreciate some help, I'm completely lost as to where the issue lies....