0

I don't know if it is a duplicate of Is it possible to dynamically build a multi-dimensional array in Java? because I don't know the

Array.newInstance(Array.class, 5);

method and I couldn't find an answer I understood on that question either but the 2 questions are definitely about the same topic

I want a multi-dimensional array to store the inputs and the inputs size is defined in the constructor like this

 double[[]] inputs;
 public AI(int[] inputSize) {
    inputs = new double[inputSize];
 }

I know the [[]] doesn't exist but is there an alternative?

(I tried to remove most of the context since I think the question will be more straightforward to answer this way)

EDIT : to be clear I don't want double[][] I want double[][][]... where the number of [] equals inputSize.size so for example : inputSize = {5,3,2,1}; => inputs = new double[5][3][2][1];

Community
  • 1
  • 1
fejfo
  • 217
  • 1
  • 7
  • Do you mean `[][]`? – Andrew Li Jul 02 '16 at 18:32
  • @AndrewL. I believe he wants `double[][][]...` where the number of [] is dynamic. In which case... hmm. I don't know. Never thought about it before! I'm leaning towards "that's not possible" but I'm sure someone has a clever solution (which potentially doesn't involve strict arrays) – nasukkin Jul 02 '16 at 18:34
  • @nasukkin I was talking about `[[]]`, `[][]` is valid – Andrew Li Jul 02 '16 at 18:35
  • @nasukkin Yes that is what I want the number of [] would equal inputSize.length – fejfo Jul 02 '16 at 18:36

0 Answers0