title: Making a HashMap from a text file using Buffered Reader?
body: <p>I am having trouble coding a method that given an argument, a file name, reads through the file which will contain words and makes a Hashmap with the key as the first letter e.g. for a word in the file such as apple , 'a' is the key and value is 'apple'. </p>
  
  <p>Code I have currently: </p>
  
  <pre><code>public class WordStore {
  HashMap&lt;String, List&lt;String&gt;&gt; map;
  File filename;
  
  public WordStore() {
       map = new HashMap&lt;String, List&lt;String&gt;&gt;();
  }
  
  public WordStore(File file) throws IOException {
      map = new HashMap&lt;String, List&lt;String&gt;&gt;();
      BufferedReader br = null;
      //k = "/Users/hon/eclipse-workspace/Assignment4/src/wordbank.txt"
      try{
          File filename = new File(k);
          FileReader fr = new FileReader(filename);
          br = new BufferedReader(fr);    
          while(br.readLine()!=" ") {
          String word ="";
          word = br.readLine();
          String key = ""+(word.charAt(0));
          map.put(key, word);
          }
  
      }
      catch(IOException e) {
          System.out.println("File not found exception caught!");
      }
      finally {
          if(br != null) {
              try {
                  br.close();
              }
          catch(IOException e) {
              e.printStackTrace();
          }
          }
      }
  
  }
  public void put(String key, String word) {
      if(map.containsKey(key)) {
          (map.get(key)).add(word);
      }
      else {
      List&lt;String&gt; names = new ArrayList&lt;&gt;();
      names.add(word);
      map.put(key, names);
      }
  }
  }
  </code></pre>
  
  <p>I have an error in the constructor WordStore(File file), at map.put(key, word) which says the method <code>put(String, List&lt;String&gt;)</code> in the type <code>HashMap&lt;String, List&lt;String&gt;&gt;</code> is not applicable for the argument (String, String). </p>
  
  <p>I tried renaming my put method so that it uses my method and not the hashmap put method but that doesn't work either.</p>