I want to cycle through/access all possible combinations of the elements in a series of Lists in a clock-like fashion, but I will not know how many Lists there will be until runtime (i.e. I can't hardcode it). Normally, if I did know how many Lists there would be, I would use nested For loops in something like this:
for(int x = 0; x < total1; x++){
for(int y = 0; y < total2; y++){
for(int z = 0; z < total3; z++){
//Handling code
}
}
}
Where the outermost loop represents the last List, and the innermost represents the first. However, because I do not know how many Lists there will be, I can't use this method, because I wouldn't know how many loops to use. Some things on the Internet said to use a recursive program that would repeatedly run for-loops, but I don't understand how this could reach the same result as the above method.
Is there a way to accomplish the same ends as the For-loops (accessing every combination of elements from the Lists, taking one element from each List) without knowing how many Lists/Loops are needed?
Edit: As an example, if I have 3 Lists, each with 4 elements:
[1,3,6,5], [0,5,8,2], [9,7,1,6]
Then my output should be, essentially, 64 Lists containing all possible examples, e.g.:
[1,0,9], [3,0,9], [6,0,9], [5,0,9],
[1,5,9], [3,5,9], [6,5,9], [5,5,9],
[1,8,9], [3,8,9], [6,8,9], [5,8,9],
[1,2,9], [3,2,9], [6,2,9], [5,2,9],
[1,0,7], [3,0,7], [6,0,7], [5,0,7] //...etc
Hope this helps!