Hi Everyone,
I'm working on a project which has a dictionary of words and I'm extracting them and adding them to an ArrayList as word objects. I have a class called Word as below.
What I'm wondering is how do I access these word objects to update the frequency? As part of this project, I need to only have one unique word, and increase the frequency of that word by the number of occurrences in the dictionary.
Word(String word)
{
this.word = word;
this.freq = 0;
}
public String getWord() {
return word;
}
public int getFreq() {
return freq;
}
public void setFreq() {
freq = freq + 1;
}
This is how I am adding the word objects to the ArrayList...I think it's ok?
String pattern = "[^a-zA-Z\\s]";
String strippedString = line.replaceAll(pattern, "");
line = strippedString.toLowerCase();
StringTokenizer st = new StringTokenizer(line);
while (st.hasMoreTokens())
{
String newWord = st.nextToken();
word.add(new Word(newWord));
count++;
}