Java ArrayList copy

前端 未结 8 875
说谎
说谎 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 15:57

    Java doesn't pass objects, it passes references (pointers) to objects. So yes, l2 and l1 are two pointers to the same object.

    You have to make an explicit copy if you need two different list with the same contents.

提交回复
热议问题