Different Array Types In Java ?

**Array is An Object (it stored inside the Heap memory)


** Normal 1D Array (We Know That


** Normal 2D Array (We Know That)


** Jagged Array (Example)


********************************************************************************

import java.math.*;


public class Jagged_Arr{

public static void main(String args[]) {

int matr[][]=new int[4][];

matr[0]=new int[4];

matr[1]=new int[2];

matr[2]=new int[3];

matr[3]=new int[2];

for(int i=0;i<matr.length;i++) {

for(int j=0;j<matr[i].length ;j++) {

matr[i][j]=(int) (Math.random()*100);

}

}

for(int row[] : matr) {

for(int ele : row) {

System.out.print(ele+ " ");

}

System.out.println();

}

}

}

********************************************************************************



** 3D Array (Exapmle)

********************************************************************************

public class Multi_3D_Arr {


public static void main(String[] args) {

int r=4,c=4,t=2;

int multi[][][]=new int [t][r][c];

for(int i=0;i<t;i++) {

for(int  j=0;j<t;j++) {

for(int k=0;k<c;k++) {

multi[i][j][k]=(int) (Math.random()*100);

System.out.print(multi[i][j][k]+" ");

}

System.out.println();

}

System.out.println();

}

}


}

*********************************************************************************

Comments

Popular posts from this blog

Collection Framework of Java

What is DBMS ?

Compiler vs Interpreter vs JIT Compiler