What’s a more efficient way of writing this method:
static Foo[][] copy2D(Foo[][] in)
{
Foo[][] ret = new Foo[in.length][in[0].length];
for(int i = 0;i < in.length;i++) {
for(int j = 0;j < in[0].length;j++) {
ret[i][j] = in[i][j].clone();
}
}
return ret;
}
If you did not have the clone() you could replace the inner for with:
But since you’re creating a new object in your innermost loop I don’t see any other way to do it.