Java copy two hash map
<p>I have a class containing Map whose key is string and value is object of another class.</p>

<pre><code>          Class Employee {
               String name;
          }

          Class Company {
              Map&lt;String, Employee&gt; m =new HashMap&lt;String, Employee&gt;();
          }
</code></pre>

<p>I have two Company objects obj1 and obj2, where I want to copy the map from one object to another object.</p>

<p>If I do any of the below things,</p>

<pre><code>         obj1 = obj2  or    
         obj1.setM(obj2.getM())   // assume we have setters and getters
</code></pre>

<p>now if I manipulate obj1's map, making the any of the value to point to different object of Employee for same Company object that obj2 has, where obj2's map is also getting affected.</p>

<p>Is there any way (other than copying key and value to new map and assigning it to object), where we can copy the map contents to another object's map such that manipulating one map doesnot affect other map. Any suggestions are really appreciated.</p>
