Sorry, me again.
Hopefully the following will be enough code for you to help me:
Map<File,Integer> fileMap = new HashMap<File,Integer>();
private void displayResults()
{
// display the top 5 entries in the map in a text area
//if (searchString.equals(fileMap.get(searchString)))
resultText.setText(""); // init text area to empty string
for (int i = 0; i < 5; i++)
{// loop to 5
String word = findHighestScore();// find most common word
System.out.println("word = " + word);
resultText.append(String.format("%s (%d)\n", word, fileMap.get(file))); // add info to textarea
fileMap.remove(word);// remove this file from map
}
}
private String findHighestScore()
{
// find the word with highest count in the map
// iterate through map, checking each word to see if it has
String highestScoredFile = null; // initialise highest word
int countHighestWord = 0;// and highest word count
for (File file: fileMap.keySet())// iterate through map
if (fileMap.get(file) > countHighestWord)
{
highestScoredFile = file.getName();
countHighestWord = fileMap.get(file);
}
return highestScoredFile;
}
Now, this line of code is not removing the entry from the map, so it is being returned 5 times:
fileMap.remove(word);// remove this file from map
The following line of code returns null as the value for "fileMap.get(file)":
resultText.append(String.format("%s (%d)\n", word, fileMap.get(file)));
Message was edited by:
nessymonster

