I have a piece of information that depends on 3 different factors (which I represent as numbers), for example,
if 0,0,0 then information is (value) if 0,0,1, then information is (value) etc.
I initially created a 3d array, and filled it with nested for loops, something like
for (int i = 0; i < maxfactor1; i++) {
for (int a = 0; a < maxfactor2; a++) {
for (int j = 0; j < maxfactor3; j++) {
test2[i][a][j] = j * 2.0;
System.out.println(test2[i][a][j]);
}
}
}
The problem is that I may not have every single combination of factors, and including them would be wrong. I searched for a dynamic implementation of the array, and found something like:
ArrayList<Integer> row = new ArrayList<Integer>();
row.add(1);
row.add(11);
row.add(111);
row.add(2);
row.add(22);
row.add(222);
ArrayList<ArrayList<Integer>> test = new ArrayList<ArrayList<Integer>>();
test.add(row);
The problem is that although I am able to store the factors, I am not able to store the value. I need to be able to easily access the factors (like in a for loop) as well as the value.
Are there any other ways to create a dynamic size array in Java so that I can refer to both factors and the value? Any advice is mostly appreciated.
ArrayList<HashMap<Integer,Integer>>