Copying a HashMap in Java

前端 未结 11 1073
灰色年华
灰色年华 2020-11-29 22:02

I am trying to keep a temporary container of a class that contains member :

HashMap myobjectHashMap

A class called my

11条回答
  •  余生分开走
    2020-11-29 22:34

    If you want a copy of the HashMap you need to construct a new one with.

    myobjectListB = new HashMap(myobjectListA);
    

    This will create a (shallow) copy of the map.

提交回复
热议问题