This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I don't see any two-dimensional arrays; "new int[]{1,2,3}" creates a one-dimensional array with three numbers in it. Creating a two-dimensional array with the bracket-initialization syntax would look like
int anar[][] = new int[][]{{1,2,3}, {4,5,6}, {7,8,9}};
This distinction [that what might be mistakenly called multidemensional arrays are in fact arrays of arrays] is important in coming to terms with the Java programming language, and is not purely academic as some might suggest.
I am then presented with some pretty generic code using arrays of arrays, and informed that
It is important to realise, that in the above code sample, there is no "2 dimensional" array. There is an array whose elements are String arrays.
However, I am never told why this is important to realize. In what instance would this knowledge influence my use of arrays? [ June 08, 2004: Message edited by: Joseph George ]
I've heard it takes forever to grow a woman from the ground
Ernest Friedman-Hill
author and iconoclast
Marshal
The difference influences what you can and can do as far as initializing and working with arrays, but mostly "around the edges." The distinction is unimportant for most straightforward uses. As the web page points out, a "2D" array doesn't have to be rectangular, and this influences how nested loops should be written, but only rare code exploits this fact.
C(++) supports both kinds of arrays, but (a) doesn't support Java's shortcut syntax for initializing the array-of-pointers-to-arrays kind, and (b) requires you to deallocate the memory for the sub-arrays manually, so in that language the distinction is much more important.
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
posted
0
[IDLE CURIOSITY] how does a non-rectangular "2D" array work? [\IDLE CURIOSITY]
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Why this code does not generate any exception?