Matrix Representation
This type of array declaration is represented in matrix form. Memory wastage is most probable to happen in this scenario and manually unassigned blocks of memory are automatically assigned to zero.
class MatrixRepresentation {
public static void main(String[] args) {
int[][] x = new int[4][4];
x[0][0] = 10;
x[0][1] = 12;
x[0][2] = 99;
x[0][3] = 89;
x[1][0] = 28;
x[1][1] = 67;
x[1][2] = 56;
x[2][0] = 80;
x[2][1] = 90;
x[3][0] = 90;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
System.out.println("x[" + i + "][" + j + "] = " + x[i][j]);
}
System.out.println();
}
System.out.println("The unassigned block of memory are assigned to zero.");
}
}
Conventional Representation
This method of declaring array is often referred as conventional way of declaring array.
class ConventionalWay{
public static void main(String[] args){
int[][] x = new int[4][3]; // The no of pairs of brackets represents the level of array i.e. dimensions.
}
}