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

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

    Suppose you have two arraylist of String type . Like

    ArrayList firstArrayList ;//This array list is not having any data.
    
    ArrayList secondArrayList = new ArrayList<>();//Having some data.
    

    Now we have to copy the data of second array to first arraylist like this,

    firstArrayList = new ArrayList<>(secondArrayList );
    

    Done!!

提交回复
热议问题