Exercise: Word Frequency Counting
Implement a function wordCount that counts the occurrence of each word in an input string array and returns a HashMap<String, Int64>.
The code on the right provides the function signature and test data. You only need to fill in the function body. Hint: iterate through the array, and for each word, if it already exists in the HashMap, increment the count; otherwise, insert an initial value of 1. This logic is the same as the tag counting on the previous page.
After completion, click run to check if the statistics are correct.
Implementation approach:
- Create an empty
HashMap<String, Int64> - Iterate through each word in the input array
- For each word, check if it's already in the map
- If it exists, increment the count; otherwise, insert initial value 1
- Return the filled
HashMap