Java:实例双数组元素值修改问题

2on*_*one 4 java arrays instance-variables

我是 Java 新手。我有一个可以为其创建实例的类。在类中,我定义了两个实例变量:

double[] array1;

double[] array2;

数组的长度相等。

Within the class I then have a method1 that first populates array1 and then another method2 in which I want to set some of the array2 values = the values in array1 (based on array element index) but also then modify (perform additional operation on) some of the values in array2 (based on array element index). I have tried to do this within method2 by first setting:

array2 = array1;

and then modifying some of the array2 values based on element index but I see that array1 has been completely modified to equal array2 so realise there is something fundamentally wrong with my approach in Java.

Usa*_*oto 5

数组Java是对象,变量只保存引用。
因此array1 = array2只将array2的引用分配给变量array1,而不复制内容......