How to place HashSets INSIDE of a HashMap?
<p>I'm trying to place a String (the individual words) and an int (their HashCodes) into a HasMap. I'm really struggling when it comes to placing items inside. </p>

<pre><code>// These approaches won't even run the code properly. 
map.put(word.hashCode(), word);

// This type of approach makes my code work, but it's obviously not adding the words in.
map.put(word.hashCode(), new HashSet&lt;String&gt;()); 
</code></pre>

<p>I've been trying a lot of different funky things here, but I can't really work out how to properly add the individual words into the map. Can someone help me understand how to first place it into the HashSet so it can be put into the map?</p>

<pre><code>import java.io.*;
import java.util.*;
class Assign004{
public static void main(String args[]){

    // INT = HASHCODE
    // STRING = WORD
    Map&lt;Integer, HashSet&lt;String&gt;&gt; map = new HashMap&lt;Integer, HashSet&lt;String&gt;&gt;();

    // READ WORDS AND PLACE THEM INTO THE MAP
    readFile(map);
}

public static void readFile(Map&lt;Integer, HashSet&lt;String&gt;&gt; map){
    String word = null;

    try{
        File file = new File("src/Assign004_FILE.txt");
        Scanner r = new Scanner(file);

        while(r.hasNext()){

            /* *******************************************************
                      TEST CODE. TO CHECK IF IT'S READING IN THE WORDS 
            word = r.next();
            int hash = word.hashCode();
            System.out.print(word);
            System.out.print(": " + hash + "\n"); 
            ******************************************************** */

            word = r.next();
            map.put(word.hashCode(), new HashSet&lt;String&gt;());
            System.out.print(map);
        }
        r.close();

    }catch(FileNotFoundException e){
        System.out.println("ERROR OPENING FILE");
    }
  }
 }
</code></pre>