Jagged Array on JAVA ( My Perspective )

The advantages of using jagged array is you can save your computer memory, because this jagged array usually used for optimisation slots of array. confuse? i hope not, let me show you some example about jagged array usage.

if we want to use an array 2 D to save this set of number

5 2 0 5 1 0 0 on the first row

0 7 2 on the second row

if we are declare and initialize int a [2] [7] we will have 4 empty array that we dont use it… agree with me?

so the wise code to optimisation of array usage slots is like this one :

public class nrp_andre_keren {

                     public static void main(String[] args) {

                               int[][] NRP = { { 5, 2, 0, 5, 1, 0, 0 }, { 0, 7, 2 }};

                               for (int i = 0; i < NRP.length; i++) {                                         for (int j = 0; j < NRP[i].length; j++) {                                          System.out.print(NRP[i][j] + " ");                                                            }                                  System.out.println(" ");                                        }                     }             }  [/sourcecode]

 

that is a simple example… for the advance, you can send an e-mail to me and we can discuss it…