I have a use case which looks something like this :
Map<String,String> pr = new HashMap<>();
pr.put("ab","ab");
pr.put("xy","xy");
Map<String,String> prNew = new HashMap<>();
prNew = pr;
prNew.remove("ab");
System.out.println(pr);
System.out.println(prNew);
This is the output i got :
{xy=xy}
{xy=xy}
But I was expecting 'pr' to remain as :
{ab=ab, xy=xy}
It looks like prNew took a reference of pr, and any modifications to prNew will modify pr as well.
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.
Any help would be greatly appreciated. Thanks.
