import java.util.Vector;
public class WordList {
private Vector words = new Vector();
private Vector counts = new Vector();
private static final Integer ONE = new Integer(1);
public int addWord(String word) {
int foundIndex = words.indexOf(word);
if (foundIndex == -1) {
words.add(word);
counts.add(ONE);
foundIndex = words.size() - 1;
}
else {
int count = ((Integer)counts.get(foundIndex)).intValue();
count++;
counts.setElementAt(new Integer(count), foundIndex);
}
return foundIndex;
}
public String toString() {
return words.toString() + counts.toString();
}
Arrays
}