java - Modification in one MultiValueMap affecting another -


i have 2 multivaluemap in class
mapa , mapb. 2 maps equal. have iterate using mapa , did changes in mapb. affecting mapa. mapa changing. why happens.

edit

simple code

multivaluemap mymap = new multivaluemap(); mymap.put("a", "1"); mymap.put("b", "2");  mymap.put("c", "3");  mymap.put("d", "4");  system.out.println("mymap => "+mymap); multivaluemap sec = mymap;  if(mymap.containskey("a")) {     sec.getcollection("a").clear();     sec.put("a", "11");   }   system.out.println(mymap); // {d=[4], a=[11], b=[2], c=[3]} system.out.println(sec); // {d=[4], a=[11], b=[2], c=[3]} 

this -- -- happens because 2 maps contain references same objects. when modify object, automatically changes in both maps.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -