I am using a short[]
array:
short[] buffer = new short[bufferSize];
I have a method that takes as a parameter type double[]
, so I cannot pass it as-is. I need to make it into a double[]
. The best thing that I've done is to make a new object and loop through and convert, like this:
double[] transformed = new double[bufferSize];
for (int j=0;j<bufferSize;j++) {
transformed[j] = (double)buffer[j];
}
I have not yet even tested the above approach, but I am wondering if there is a better way to do this?
Thanks.
The answer provided by Laurence is correct and should be accepted, but it's worth noting that there is more than one way to copy an array in Java. See this article for an explanation of each method.
That's as good as it gets, though you can just use
buffer.length
instead ofbuffersize
.