Java ArrayList copy

前端 未结 8 632
说谎
说谎 2020-11-22 15:19

I have an ArrayList l1 of size 10. I assign l1 to new list reference type l2. Will l1 and l2 po

相关标签:
8条回答
  • 2020-11-22 16:00

    Another convenient way to copy the values from src ArrayList to dest Arraylist is as follows:

    ArrayList<String> src = new ArrayList<String>();
    src.add("test string1");
    src.add("test string2");
    ArrayList<String> dest= new ArrayList<String>();
    dest.addAll(src);
    

    This is actual copying of values and not just copying of reference.

    0 讨论(0)
  • 2020-11-22 16:01

    Try to use Collections.copy(destination, source);

    0 讨论(0)
提交回复
热议问题