title: HashMap and classes
body: <p>I am trying to use a HashMap to store some classes.
  here is a view of my simplified code.</p>
  
  <pre><code>HashMap&lt;Integer, MyClass&gt; map = new HashMap&lt;Integer, MyClass&gt;
  MyClass myClass = new MyClass();
  for (int i = 0; i&lt;MAX;i++){
      myClass.counter=i;
      map.put(i, myClass);
      myClass.modifySomeInternalParameters(i);
      myClass.anotherCounter+(i*2);
  }
  </code></pre>
  
  <p>Whenever I reach the last statement, anotherCounter gets updated for ALL the entries in the Map. (same for counter actually)
  I have tried changing the put statement to </p>
  
  <pre><code>map.put(i, new MyClass (myClass));
  </code></pre>
  
  <p>to no avail.
  I have the feeling that the HashMap does not create a copy of myClass to store it, but rather looks at its content in memory. Is there a way to prevent this if I don't want to recreate myClass and repopulate it each time.
  Using 'Clone' in my loop sounds ugly.</p>
  
  <p>TIA</p>