mohammad shaid wrote:i came across int[][] myArray=new int[3][]; its given in the book that only first brackets are given a size and thats acceptable in java since the JVM needs to know only the size of the object assigned to variable myArray.. but i tried to put the size on right bracket too and i dint get compiler error.
There is also a bit of syntactic sugar going on -- to make your life easier, and make it easier to read. Basically, when you do this...
You are instantiating an array of size three, which contains references to int arrays, but are assigned to null.
When you do this...
It does the same thing, but it goes one step further. It will then instantiate a bunch of int arrays of size 7, and assign one to each of the three elements of the int array array.
It certainly looks cleaner than the first case, followed by a loop to instantiate the individual elements.
Henry