title: Copying a HashMap in Java
body: <p>I am trying to keep a temporary container of a class that contains member :</p>
  <pre><code>HashMap&lt;Integer,myObject&gt; myobjectHashMap
  </code></pre>
  <p>A class called myobjectsList</p>
  <p>Then I do</p>
  <pre><code>myobjectsListA = new myobjectsList();
  myobjectsListB = new myobjectsList();
  </code></pre>
  <p>then: Add some hashmap items to A (like 2)</p>
  <p>then:</p>
  <pre><code>myobjectListB = myobjectListA; //B has 2
  </code></pre>
  <p>then: Add hashmap items to A (like 4 more)</p>
  <p>then: return A to the items stored in B</p>
  <pre><code>myobjectListA = myobjectListb;
  </code></pre>
  <p>But when I do this, B grows with A while I am adding hashmap items to A.
  A now has 6 items in it because B had 6.</p>
  <p>I want A to still have the original 2 at the end after last assignment.
  In C++ I would use copy with objects, what is the java equivalent?</p>
  <p>Added: OK I left something out explaining this. <code>MyObjectsList</code> does not contain the HashMap, it is derived from a class <code>MyBaseOjbectsList</code> which has the HashMap member and <code>MyObjectsList</code> extends <code>MyBaseOjbectsList</code>. Does this make a difference?</p>