title: Java dictionary<String, List<Object>>
body: <p>I was making a game with XNA game studio and now I want to rewrite it in Java. It's something like a 2D Minecraft clone. For collision detection, I have to loop through all blocks in the game to check on whether the player is colliding with a block. With a huge number of blocks, it is impossible to do so, so I made a grid system. I divided the world into grids which contain blocks, and put them into a dictionary.</p>
  
  <pre><code>Dictionary&lt;string, List&lt;Block&gt;&gt; gameBlocks;
  </code></pre>
  
  <p>Now I have only to loop through the blocks in the current grid.</p>
  
  <p>This is the method to register a block:</p>
  
  <pre><code>public void RegisterBlock(Block block)
  {
      idX = (int)(block.blockPosition.X / width);
      idY = (int)(block.blockPosition.Y / height);
      string id = idX.ToString() + "_" + idY.ToString();
      if (gameBlocks.ContainsKey(id))
      {
          gameBlocks[id].Add(block);
      }
      else
      {
          gameBlocks.Add(id, new List&lt;Block&gt;());
          gameBlocks[id].Add(block);
      }
  }
  </code></pre>
  
  <p>Now I am trying to rewrite it in Java but I don't know how to put something into a Dictionary.</p>