View RSS Feed

Java Array

Two-Dimensional Arrays

Rate this Entry
by , 03-04-2012 at 10:23 AM (585 Views)
2 dimensional arrays are known to be the array of arrays. Number of array types is present, for example:

  1. Array of Strings
  2. Array of ints
  3. Array of Objects



Array of int consists of type int[]. Two dimensional array will have int[][]. It might also be known as array of arrays of the ints. Such type of arrays are known as 2D arrays.

Command:
int[][] array = new int[5][6];
Array or variable of type int[][] gets declared. Variable is initialized so that to refer it for a new object created.
Int [5][6], it has been indicated that five arrays of ints are present, in “array”. Six ints are present in every array present.
2D arrays are processed by the nested loops. “Nested” loops are the loops which are present in any loop. Array’s processing is explained by the given code.
Java Code:
int[][] a2 = new int[10][5];
 // print array in rectangular form
 for (int i=0; i<a2.length; i++) {
     for (int j=0; j<a2[i].length; j++) {
         System.out.print(" " + a2[i][j]);
     }
     System.out.println("");
 }

Submit "Two-Dimensional Arrays" to Facebook Submit "Two-Dimensional Arrays" to Digg Submit "Two-Dimensional Arrays" to del.icio.us Submit "Two-Dimensional Arrays" to StumbleUpon Submit "Two-Dimensional Arrays" to Google

Comments