title: Comparing hashmap key with words in text file and updating value
body: <p>I've been using a hashmap to store unique words from a text file. Now, I need to compare each word in the hashmap with another larger text file and keep track of the frequency of each word as it appears in the text file. </p>
  
  <p>Whilst adding to the hashmap at first, I only insert the key and set the value to 0. My plan is to use 'value' as the frequency of each word in the larger text file.</p>
  
  <p>My attempt is as follows; I first use scanner to read the original file and store the words into the hashmap. Next, I use scanner again, but this time associated with the larger text file. From here on, I'm a bit stuck. I don't know how to update the 'value' and index the 'key'.</p>
  
  <p>Here is what I have;</p>
  
  <pre><code>Scanner fileScanner = new Scanner (new File (fileName));
  fileScanner.useDelimiter (" ");
  
  while (fileScanner.hasNext()) {
      for (int i = 0; i &lt; hashmap.size(); i++) {   //This I use to index the key field
          if (hashmap.get(i).equals(fileScanner.next().toString()) {
              int freq ++;
              //How do I update the value field of the corresponding value?
          }
      }
  }
  </code></pre>
  
  <p>Now, obviously, nothing in the above code works, and I'm having some problems with figuring out a way. Could anyone please help me?</p>