Assigning Hashmap to Hashmap

后端 未结 5 1281
轻奢々
轻奢々 2020-12-14 10:13

I have a hashmap which I want to copy for other use. But whenever I copy it and reuse it, it also changes the original one. Why is that?

    do {
                    


        
5条回答
  •  萌比男神i
    2020-12-14 10:27

    This might be coming a bit late, but another simple solution will be to Serialize the map to an output Stream and de-serialize it to a new Map Object. Thats also one of the easiest ways to break the singleton pattern.

提交回复
热议问题