I have a String which contains arrays. Example:
"[[1, 2], [4, 5], [7, 8]]"
Now, I want to make an actual Java array out of this. I have created a function to get the dimensions and a recursive function to get each and every element of the array. Thus, I have every 1-D array created, but I would like to know if there is a way in Java to create an array of the dimension that I found during the runtime? The dimension are returned as an array. Like, for the above example the dimension is:
[3, 2]
EDIT:
Is there a way to create an actual array from this information? The dimension [3, 2] is just an example. I can have [3, 2, 4, 5] as well. Can an array be generated from this information during the runtime? I do not have this information during compile time.
There is some problem, I cannot comment on answers. So, I am editing here.
解决方案
If you are doing numeric work then you should probably use a library. For example my open source library Vectorz provides proper support for multidimensional arrays / matrices (with doubles).
Then you can just do something like:
INDArray m=Arrayz.parse("[[1, 2], [4, 5], [7, 8]]");
The INDArray object encapsulates all the multidimensionality so you don't need to worry about writing big nested loops all the time, plus it provides a lot of other functions and capabilities that normal Java arrays don't have.