What is the difference between these blocks of code?

So, I looked through this block of code several times in the book I am reading:

int[][] someArray = new int[size][];
for(int i=0; i<size; i++)
   someArray[i] = new int[size];

I see no difference between this and the following declaration:

int[][] someArray = new int[size][size];

Did I miss something? Is there a reason why I should use the long code block above?

Thank,

+5
source share
4 answers

You can create ragged or jagged arrays with the first construct

+6
source

, . , - ( ). , ( )

1 2 3

1 2

4 4 5 6 2 3 5

4 5 1

2 2 5 2

. , , .

, , , .

+2

here. , .

+1

- - - .
-, .

( ): public static void main (java.lang.String []); :  0: iconst_3  1: anewarray # 2;// "[I"  4: astore_1  5: return

:

0: iconst_3 1: iconst_3 2: multianewarray # 2, 2;//class "[[I" 6: astore_1 7: return

==================

, , , "" . , Google, = 10000000. .

+1

All Articles