I need a large series of arrays, right now I am creating them manually:
int[] row1 = new int[3];
int[] row2 = new int[3];
int[] row3 = new int[3];
I would like to create these in an array, something like this:
public final int SIZE = 3;
for (int i = 1;i <= 3;i++)
int[] row[i] = new int[3];
But I am not sure how to generate arrays in a loop.
How do I do this?
Specifically, how do I generate dynamic identifiers on each iteration?
Specifically, how do I generate dynamic identifiers on each iteration?
You don't. Instead, you realize that you've actually got a collection of arrays. For example, you could have:
int[][] rows = new int[3][3];
Or:
List<int[]> rows = new ArrayList<>();
for (int i = 0; i < 3; i++) {
rows.add(new int[3]);
}
See more on this question at Stackoverflow