how-to

Arrays

How to create multidimensional array

Multidimensional array you can declare and initialize by this way:

/* -- declare and initialize multidimensional array */
    
int[][] doubleArray = 
{
  { 1, 3, 5 },
  { 2, 4, 6 }
};
      
/* -- go throught multidimensional array (by rows) */
    
for ( int iRow = 0; iRow < doubleArray.length; iRow++ ) {
  int[] iArray = doubleArray[ iRow ];
      
  System.out.println( Arrays.toString( iArray ) );    
}

In this example was created two-dimensional int array. The example output will be:

[1, 3, 5]
[2, 4, 6]