Assigning a map to a new map in java, and then changing the new map also changes original map : <p>I have a use case which looks something like this :</p>

<pre><code>    Map&lt;String,String&gt; pr = new HashMap&lt;&gt;();
    pr.put("ab","ab");
    pr.put("xy","xy");
    Map&lt;String,String&gt; prNew = new HashMap&lt;&gt;();
    prNew = pr;
    prNew.remove("ab");
    System.out.println(pr);
    System.out.println(prNew);
</code></pre>

<p>This is the output i got :</p>

<pre><code>{xy=xy}
{xy=xy}
</code></pre>

<p>But I was expecting 'pr' to remain as :</p>

<pre><code>{ab=ab, xy=xy}
</code></pre>

<p>It looks like prNew took a reference of pr, and any modifications to prNew will modify pr as well.</p>

<p>So how do i get around this? In my use case I need to take a copy of pr and make some changes but it should not affect the original pr.</p>

<p>Any help would be greatly appreciated. Thanks.</p>
