+ 1

Mutidimensional Arrays (I don't get this, please help)

Hi, my name is Paul, im learning Java, and I've arrived at the part with the mutidimensional Arrays, but I don't see the logic behind it. Could anyone please explane it to me. Thank you!

31st Jan 2017, 5:54 PM
Paul Becher Herrero
Paul Becher Herrero - avatar
1 Antwort
+ 4
I think its best to give you an example: int [ ] [ ] twoDimArray; is a variable for a two-dimensional array. To create the object you write the following: int [ ] [ ] twoDimArray = new int [5] [8]; this means, that you created an array whose 5 elements are arrays themselves. Each one of those arrays has 8 elements. Then you can write this for example: twoDimArray [3][6] = 34; you now gave the 7th element ( the elements of an array start with 0, so its the 7th not the 6th element) of the array that represents the 4th element of the 'main' array the value 34. Same goes for a 3 or even more-dimensional array. multDimArray[3][6][4] = 21; means you give the fifth element of the 7th second level array element which is itself the 4th array in the first level array. int [ ] [ ] [ ]multDimArray = new int [5] [8] [4]; means that multDimArray is an array of 5 elements which are themselves arrays of 8 elements. These 8 elements are arrays too, which have 4 elements each.
31st Jan 2017, 6:44 PM
Lorenz Meierhofer
Lorenz Meierhofer - avatar