I'm using Apache math library for matrices and one here's one of the methods I'm trying to use:
MatrixUtils.createRealDiagonalMatrix(double[] diagonal)
I don't know the size at compilation time so I'm using ArrayList<Double>
to store the diagonal and later I want to pass that as parameter to the above function. How can I cast the ArrayList
to double[]
? I've tried:
ArrayList<Double> arr = new ArrayList<Double>(n);
... // Populate arr
MatrixUtils.createRealDiagonalMatrix(arr.toArray(new Double[n]));
But I'm getting a type mismatch error since Double[] and double[] are different.