im trying to build a text classification program that reads in a text file, tokenises it and stores it in a hashmap. Along the way i would like to instantiate another class which reads a text file full of commonwords. I would then like to remove these common words from the initial hashmap. I have set up two classes one called CommonWords.java and the other called Train.java. I am getting an error which i have posted after my code.
I think i have something wrong with the adding of the commonwords to the hashtable..
is missing before usage. Next time mark line 26, to make it more easy to find it. Read the message. Try to understand it yourself. Use a tool which has linenumbers. (Everything except Notepad has linenumbers).
thats great am able to get the items added in the commonwords class. although im still having a problem removing the items from the initial hashmap. i have changed it slightly now to use an arraylist for the commonwords instead of a hash table as i had no need for a value next to the string.
im not sure whether the remove statement is going to work now. as counts is a hashmap and cwords is an arraylist of string objects.
so problems at the moment are that i cant instantiate the arraylist and cannot remove commonwords from hashmap.
Although this thread is a little old, I'd just like to point out that ArrayList already overrides the toString() method to print out all the elements it contains. In fact, most Collection classes do, afaik. This means you don't have to iterate over a Collection manually when you write a toString() method for your own class.