Jagged Arrays Definition
-
Hello everyone. As far as I know Jagged array is also called "array of array" does that mean that I can use a definition like int[][][] Jagged Array = new int[3][3][]? And does it mean "array of array of array"? I mean if I use something like that does it contain 9 arrays in it? if I'm wrong how can I define something like that? Thanks in advance!
-
Hello everyone. As far as I know Jagged array is also called "array of array" does that mean that I can use a definition like int[][][] Jagged Array = new int[3][3][]? And does it mean "array of array of array"? I mean if I use something like that does it contain 9 arrays in it? if I'm wrong how can I define something like that? Thanks in advance!
All of your answers can be found on MSDN: http://msdn.microsoft.com/en-us/library/2s05feca.aspx[^]
-
Hello everyone. As far as I know Jagged array is also called "array of array" does that mean that I can use a definition like int[][][] Jagged Array = new int[3][3][]? And does it mean "array of array of array"? I mean if I use something like that does it contain 9 arrays in it? if I'm wrong how can I define something like that? Thanks in advance!
Almost, yes it would be "an array of (array of (array of ints))" (with parentheses for extra clearness) However, you can only create 1 array at the time, so you can make a
new int[3][][]
, but then you'd have to loop over it and fill every entry with anew int[3][]
You would then have 9 places in which you could put an "array of int" (but they are allnull
) so only 1 + 3 arrays in total (the outer array and the three middle arrays). (until you also create the arrays of ints) It's not all that useful to do this though (when all sub-arrays have the same length), you might as well make anew int[9][]
and index it with[3*i+j]
instead of[i][j]
, which takes much less code (you don't have to fill the outer array with arrays). You could extend this to three dimensions if all arrays of int will be the same length. -
Almost, yes it would be "an array of (array of (array of ints))" (with parentheses for extra clearness) However, you can only create 1 array at the time, so you can make a
new int[3][][]
, but then you'd have to loop over it and fill every entry with anew int[3][]
You would then have 9 places in which you could put an "array of int" (but they are allnull
) so only 1 + 3 arrays in total (the outer array and the three middle arrays). (until you also create the arrays of ints) It's not all that useful to do this though (when all sub-arrays have the same length), you might as well make anew int[9][]
and index it with[3*i+j]
instead of[i][j]
, which takes much less code (you don't have to fill the outer array with arrays). You could extend this to three dimensions if all arrays of int will be the same length. -
Hello everyone. As far as I know Jagged array is also called "array of array" does that mean that I can use a definition like int[][][] Jagged Array = new int[3][3][]? And does it mean "array of array of array"? I mean if I use something like that does it contain 9 arrays in it? if I'm wrong how can I define something like that? Thanks in advance!
Hi Sokka93, For an excellent discussion of "jagged arrays" compared to "multidimensional" arrays, see : [^] For performance comparisons of jagged and multidimensional arrays see : [^] best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
-
Hi Sokka93, For an excellent discussion of "jagged arrays" compared to "multidimensional" arrays, see : [^] For performance comparisons of jagged and multidimensional arrays see : [^] best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844