Consider the following method that finds matching words in a file and writes them in another file.
Now, lets say the input file (is the file which i m scanning for matching words) has four occurrences of the word "Alice". The above method finds these four occurrences. What i would like to achieve now is how do i restrict the matched word writing into a file to only one time. What i mean is that the above method finds four occurrences of the word "Alice". Now i want the matched word Alice to be written only once in a file and also is there a way by which i could keep track of the counter. So that the output file should contain something like "Alice (found) 4 times..."
Any pointers or hints or suggestions are most welcome.
Ashish Dutt wrote:Thanks Jan, appreciated. :-)
I will have to do some reading on that and see how it could be implemented.
Jan's advice is exactly what I would have suggested, except that I would advise making it a Map<String, AtomicInteger>, because AtomicInteger's are mutable. With Integers, you'll have to do a lot of replacement.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here