English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

This question deals with the Java 2 Standard Edition for multi-dimensional arrays?

2006-06-11 06:34:10 · 3 answers · asked by tjhauck2001 2 in Computers & Internet Programming & Design

3 answers

Just adding to the answer given by Sean I.T.

Because in Java, a multidimensional array is a single dimensional array having elements as array, its possible to have a two dimensional array that is not symmetrical.

Consider following code,

int[][] multiArr = new int[2][];

multiArr[0] = new int [20];
multiArr[1] = new int [15];

in this case, the array is a two dimensional with two rows. But its not symmetrical. First row is 20 columns whereas second is 15. This is an example of a ragged array.

2006-06-11 10:53:08 · answer #1 · answered by ritesh10dulkar 2 · 0 0

All array objects in Java encapsulate one-dimensional arrays. However, the component type of an array may itself be an array type. This makes it possible to create array objects whose individual components refer to other array objects. This is the mechanism for creating multi-dimensional or ragged arrays in Java.

Such a structure of array objects can be thought of as a tree of array objects, with the data being stored in the array objects that make up the leaves of the tree.

For example, we could create a lower triangular array, allocating each row "by hand" as follows.

int[][] tri;
tri = new int[10][]; // allocate array of rows
for (int r=0; r tri[r] = new int[r+1];
}

// print the triangular array (same as above really)
for (int r=0; r for (int c=0; c System.out.print(" " + tri[r][c]);
}
System.out.println("");
}

2006-06-11 06:48:05 · answer #2 · answered by Sean I.T ? 7 · 0 0

What Is Ragged

2016-10-17 23:25:31 · answer #3 · answered by ? 4 · 0 0

fedest.com, questions and answers