Deep copy and shallow copy of map in java

Map shallow copy with "=" for assignment

 

Simple types can implement deep copying using the putAll method of Map.

 

When the object type is operated, the copied map modifies the value in it, and as a result, the original map is also changed, which cannot achieve deep copying. The reason is that we can know that a person is an object. When he is new, there will be a corresponding memory address corresponding to him. After directly modifying the content of this object, the object originally stored in the map still points to this address, so it will Affects the objects stored in the original map.

 

Guess you like

Origin blog.csdn.net/qq_23974323/article/details/106766208