X1674: Build Map with counts

Problem Description

Write a method buildMap() that receives an ArrayList<String> of words and returns a HashMap with all the words in the array list stored in a HashMap<String, Integer> where the key of the hashmap is the word from the input array and the value is the number of times that word appears in the array.

Method Signature

public HashMap<String, Integer> buildMap(ArrayList<String> words)

You must use a HashMap<String, Integer> to:

  • Count the frequency of each word in the array list words.
  • Return the hashmap created.

Constraints

  • The argument words is never null, but might have 0 values.
  • Each element in the words array list contains a string. The elements are never null.
  • Your solution must be case-INsensitive, that is "HELLO" and "Hello" are the same word so you should process it as the same item.

Documentation

Your Answer:

Feedback

Your feedback will appear here when you check your answer.