reliableNeighborValues

reliableNeighborValues

我经常使用ArrayUtils.add(double[], double)。显然我对为什么它在这里不起作用有一个盲点。有人可以帮忙吗?

double[] reliableNeighborValues = new double[1];
for (int j = 0; j < 8; j++) {
    if (pixelInfo[j] > 0) {
        System.out.println("pre add array length "+reliableNeighborValues.length);
        for (int k = 0; k < reliableNeighborValues.length; k++) {
            System.out.println("-- "+reliableNeighborValues[k]);
        }
        ArrayUtils.add(reliableNeighborValues, pixelInfo[j]);
        System.out.println("reliable neighbor "+j+" "+pixelInfo[j]+" array length "+reliableNeighborValues.length);
        for (int k = 0; k < reliableNeighborValues.length; k++) {
            System.out.println("-- "+reliableNeighborValues[k]);
        }
    }
}


输出:

pre add array length 1

-- 0.0

reliable neighbor 0 5.3364882 array length 1

-- 0.0

最佳答案

数组无法在Java中扩展,因此该方法返回您当前正在丢弃的数组的更新副本。

  reliableNeighborValues =
     ArrayUtils.add(reliableNeighborValues, pixelInfo[j]);


与字符串操作函数相同。

09-11 04:17