Campbell Ritchie

Marshal

Posts: 58831

179

Campbell Ritchie

Marshal

Posts: 58831

179

posted 9 years ago

Can you write a for loop to iterate through an ordinary array with the .length field?

Write down an ordinary array on paper, maybe int[] array = new int[]{1, 2, 3, 4}.

Now write down a 2-subscript array on paper, maybe int[][] numbers = new int[][]{{1, 2, 3}, {4, 5}, {}, {6, 7, 8, 9, 10}, {11}}. That is an array of arrays.

Now write down each element of the outer array, numbers[0], numbers[1], etc, on your paper.

Now you see you will have to initialise numbers to new int[9970][] then you can iterate through numbers and initialise numbers[0], numbers[1], numbers[2] etc etc. Work out what you would have to initialise numbers[0] to . . .

Write down an ordinary array on paper, maybe int[] array = new int[]{1, 2, 3, 4}.

Now write down a 2-subscript array on paper, maybe int[][] numbers = new int[][]{{1, 2, 3}, {4, 5}, {}, {6, 7, 8, 9, 10}, {11}}. That is an array of arrays.

Now write down each element of the outer array, numbers[0], numbers[1], etc, on your paper.

Now you see you will have to initialise numbers to new int[9970][] then you can iterate through numbers and initialise numbers[0], numbers[1], numbers[2] etc etc. Work out what you would have to initialise numbers[0] to . . .

Campbell Ritchie

Marshal

Posts: 58831

179

Campbell Ritchie

Marshal

Posts: 58831

179

posted 9 years ago

You have correctly created a 2-subscript array Now write it out on paper, and work out its size. What is the size of "data" and what is the size of "data[0]?" What size array does your Table require?

And surely you mean {name, start, length} rather than {String name, int start, int length}? That initialisation will only work with versions of Java after auto-boxing was introduced.

And surely you mean {name, start, length} rather than {String name, int start, int length}? That initialisation will only work with versions of Java after auto-boxing was introduced.