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

后端 未结 12 1667
傲寒
傲寒 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:15

    Supopose you want to copy oldList into a new ArrayList object called newList

    ArrayList newList = new ArrayList<>() ;
    
    for (int i = 0 ; i
    
    

    These two lists are indepedant, changes to one are not reflected to the other one.

    提交回复
    热议问题