Can any one tell me what is the problem in my program?
String a[],b[];
int c[] = new int[b.length];
for (int j = 0; j < a.length; j++) {
for (int k = 0; k < b.length; k++) {
if (b[k].equals(a[j])) {
c[k]++;
} else {
c[k] = 0;
}
}
}
I have thousands of words stored in a HashMap
. Now I want to check in every file that how many time one word occurred from allWords
.
Can you point out mistake in my program or give me your idea that how I can do it?
You could count words while reading your files and store on a Map already.. Assuming last word on file is "-1" and there's only one word in a line, even if the word is "happy birthday", I'd do something like this:
I think this line is resetting your counters unnecessarily:
Try removing it:
If you want to keep a separate count for each word in each file then you will need to use two dimensional array.
You can then access it using
newData[j][k]
.