I use ArrayUtils.add(double[], double)
with some frequency. Apparently I have a blind spot for why it's not working here. Can anyone help?
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]);
}
}
}
Output:
pre add array length 1
-- 0.0
reliable neighbor 0 5.3364882 array length 1
-- 0.0
Arrays cannot be expanded in Java, so the method returns an updated copy of the array, that you are currently discarding.
reliableNeighborValues =
ArrayUtils.add(reliableNeighborValues, pixelInfo[j]);
Same deal as with the String manipulation functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With