title: Word Count Program using HashMaps
body: <pre><code>import java.io.*;
  import java.util.*;
  
  public class ListSetMap2 
  {
      public static void main(String[] args)
      {
          Map&lt;String, Integer&gt; my_collection = new HashMap&lt;String, Integer&gt;();
          Scanner keyboard = new Scanner(System.in);
  
          System.out.println("Enter a file name");
          String filenameString = keyboard.nextLine();
          File filename = new File(filenameString);
          int word_position = 1;
          int word_num = 1;
  
          try
          {
              Scanner data_store = new Scanner(filename);
              System.out.println("Opening " + filenameString);
              while(data_store.hasNext())
              {
                  String word = data_store.next();
                  if(word.length() &gt; 5)
                  {
                      if(my_collection.containsKey(word))
                      {
                          my_collection.get(my_collection.containsKey(word));
                          Integer p = (Integer) my_collection.get(word_num++);
                          my_collection.put(word, p);
                      }
                      else
                      {
                          Integer i = (Integer) my_collection.get(word_num);
                          my_collection.put(word, i);
                      }
                  }
              }
          }
          catch (FileNotFoundException e)
          {
              System.out.println("Nope!");
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to write a program where it inputs/scans a file, logs the words in a HashMap collection, and count's the times that word occurs in the document, with only words over 5 characters being counted. </p>
  
  <p>It's a bit of a mess in the middle, but I'm running into issues on how to count the number of times that word occurs, and keeping a individual count for each word. I'm sure there is a simple solution here and I'm just missing it. Please help!</p>