Why does one arraylist change when a copy of it is modified

后端 未结 6 1734
傲寒
傲寒 2020-12-11 08:52

Its probably a very simple one but its\' still confusing me!

import java.util.ArrayList;

public class Sample {
    ArrayList i = new ArrayLis         


        
6条回答
  •  猫巷女王i
    2020-12-11 09:32

    The Object is not cloned, just an additional object reference has been added. Since ArrayList is not immutable, any change to the object is reflected in both the object references.

提交回复
热议问题