How do I copy the contents of one ArrayList into another?

后端 未结 12 1671
傲寒
傲寒 2020-11-27 10:46

I have some data structures, and I would like to use one as a temporary, and another as not temporary.

ArrayList myObject = new ArrayList

        
      
      
      
12条回答
  •  难免孤独
    2020-11-27 11:18

    You need to clone() the individual object. Constructor and other methods perform shallow copy. You may try Collections.copy method.

提交回复
热议问题