class return [D@15db9742
class return [D@15db9742
我有一个简单的 class 名为 "Trida"
public class Trida {
public double[] append(double[] pole1, double[] pole2){
int length = pole1.length + pole2.length;
double[] pole3 = new double[length];
for (int i = 0; i < pole1.length; i++){
pole3[i] = pole1[i];
pole3[i + 1] = pole2[i];
}
return pole3;
}
public static void main(String[] args) {
Trida trida = new Trida();
double[] pole1 = {1.0, 3.0};
double[] pole2 = {2.0, 4.0};
System.out.println(trida.append(pole1, pole2));
}
当我 运行 此代码时,终端显示 [D@15db9742,但我想要这样的打印字段 - [1.0, 2.0, 3.0, 4.0]
你能帮助我吗?
Arrays.toString(trida.append(pole1, pole2))
也看看here。
In Java, arrays don't override toString(), so if you try to print one directly, you get weird output including the memory location.
我有一个简单的 class 名为 "Trida"
public class Trida {
public double[] append(double[] pole1, double[] pole2){
int length = pole1.length + pole2.length;
double[] pole3 = new double[length];
for (int i = 0; i < pole1.length; i++){
pole3[i] = pole1[i];
pole3[i + 1] = pole2[i];
}
return pole3;
}
public static void main(String[] args) {
Trida trida = new Trida();
double[] pole1 = {1.0, 3.0};
double[] pole2 = {2.0, 4.0};
System.out.println(trida.append(pole1, pole2));
}
当我 运行 此代码时,终端显示 [D@15db9742,但我想要这样的打印字段 - [1.0, 2.0, 3.0, 4.0] 你能帮助我吗?
Arrays.toString(trida.append(pole1, pole2))
也看看here。
In Java, arrays don't override toString(), so if you try to print one directly, you get weird output including the memory location.