In JavaScript, we can flexibly define arbitrarily, highly nested arrays. For example, the following.
var arr1 = [ [0, 1], [2, 3] ];
var arr2 = [
[ [0, 1], [2, 3] ],
[ [4, 5], [6, 7] ]
];
Is it possible to define something like this in Java for a field of a class? The field must be able to store arbitrary dimensions/depths of nested arrays.
I was thinking about using a List of Lists.
List<List<Integer>> arr = new ArrayList<>();
However, this is in some sense, only a 2D matrix. Note that the index is significant (it has meaning) for my use case.
I suppose I can also create a Tree structure, but that might require some non-trivial work to get it right.
public class Node {
int index; //like the index of an array i want, unique amongst nodes of same level sharing a common parent
List<Integer> values; //the actual elements, if any
List<Node> children; //nesting deeper
}
Any tips are appreciated.