title: Java HashMap in Hashmap.Store all Coordinates of Pixels
body: <p>i have a problem regarding pixel analysis for an image.</p>
  
  <p>I am trying to analyse every pixel that is white (R=255,G=255,B=255).</p>
  
  <p>The problem is the storing/ reading of these data.</p>
  
  <pre><code>for (int i = 0; i &lt;= Map.getHeight(); i++) {
              for (int j = 0; j &lt;= Map.getWidth(); j++) {
                  if (Map.getColor(j, i).getBlue() == 255 &amp;&amp; Map.getColor(j, i).getRed() == 255
                          &amp;&amp; Map.getColor(j, i).getGreen() == 255)
                  {
  //                  coordsX = new HashMap&lt;&gt;();
                      coordsX.put(j, new Rectangle(j, i, 5, 5));
  
  
                  }
  
              }
              coordsY.put(i, coordsX);
          }
          System.out.println();
      }
  </code></pre>
  
  <p>The reading function is the following:</p>
  
  <pre><code>for (Entry&lt;Integer, HashMap&lt;Integer, Rectangle&gt;&gt; e : coordsY.entrySet()) {
              // HashMap&lt;Integer, Rectangle&gt; coordsX = coordsY.get(y);
              HashMap&lt;Integer, Rectangle&gt; coordsX = e.getValue();
              if (coordsX != null) {
                  for (Entry&lt;Integer, Rectangle&gt; entry : coordsX.entrySet()) {
                      Rectangle rect = entry.getValue();
                      g.setColor(Color.red);
                      g.draw(rect);
                      if (this.car2.intersects(rect)) {
                          intersectsTrack = true;
                      }
  
                  }
              }
          }
  </code></pre>
  
  <p>The problem is that when i outline:</p>
  
  <pre><code>coordsX = new HashMap&lt;&gt;();
  </code></pre>
  
  <p>like done above, i only get all one x value for one y value
  <a href="http://i.stack.imgur.com/jQtvM.png" rel="nofollow">example</a>.</p>
  
  <p>If i dont outline this line it is the other way around.
  <a href="http://i.stack.imgur.com/vbO32.png" rel="nofollow">example</a>.</p>
  
  <p>Can you help me fixing this problem?</p>
  
  <p>Kind Regards</p>