Basically all you need to do is this:
for (int i = 0; i < ec.size(); i++) {
Double[] boxedRow = ec.get(i);
double[] unboxedRow = new double[boxedRow.length];
for (int j = 0; j < boxedRow.length; j++)
unboxedRow[j] = boxedRow[j];
ei[i] = unboxedRow;
}
You're having trouble because of boxing / unboxing. Manually unboxing the Doubles to doubles allows us to convert the array to the right type.
An alternate solution would be this:
public ArrayList<Double[]> ec;
public Double[][] ei; // no need to unbox
// ...
for (int i = 0; i < ec.size(); i++) {
ei[i] = ec.get(i);
}
I'll add that your current solution is not a 2D ArrayList; it is an ArrayList of Double arrays. It looks like what you might be trying to do is something like this:
public ArrayList<ArrayList<Double>> ec;
public double[][] ei;
// ...
for (int i = 0; i < ec.size(); i++) {
ArrayList<Double> row = ec.get(i);
Double[] rowArray = row.toArray(new Double[row.size()]);
double[] unboxedRow = new double[rowArray.length];
for (int j = 0; j < rowArray.length; j++)
unboxedRow[j] = rowArray[j];
ei[i] = unboxedRow;
}
Which, again, could potentially be this:
public ArrayList<ArrayList<Double>> ec;
public Double[][] ei;
// ...
for (int i = 0; i < ec.size(); i++) {
ArrayList<Double> row = ec.get(i);
ei[i] = row.toArray(new Double[row.size()]);
}
Finally, please note that when you instantiate a new Double[], the arrays initialize to null and not to 0. If you try the following, you'll get a NullPointerException, though it will compile.
Double[] boxedArray = new Double[1];
double unboxed = boxedArray[0]; // equiv to "double unboxed = null;"
You need to be careful when unboxing, and make sure that you are handling nulls correctly.