This is a discussion on Arrays in Java within the Java Programming forums, part of the Software Development category; Hi all, let us start explonation and samples of 2 dimensional array and multidimensional array in java here. Anybody can ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hi all, let us start explonation and samples of 2 dimensional array and multidimensional array in java here. Anybody can share their knowledge here. |
|
#2
| |||
| |||
| Multi-dimensional arrays Java, as with most languages, supports multi-dimensional arrays - 1-dimensional, 2-dimensional, 3-dimensional, ... This discusses 2-dimensional arrays, but the same principles apply to higher dimensions.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#3
| |||
| |||
| 2-dimensional arrays 2-dimensional arrays are usually represented in a row-column approach on paper, and the terms "rows" and "columns" are used in computing. Arrays of arrays There are two ways to implement 2-dimensional arrays. Many languages reserve a block of memory large enough to hold all elements of the full, rectangular, array (number of rows times number of columns times the element size). Java doesn't do this. Instead Java builds multi-dimensional arrays from many one-dimensional arrays, the so-called "arrays of arrays" approach. [C++ supports both styles.] There are a couple of interesting consequences of this: Rows may be different sizes. Also, each row is an object (an array) that can be used independently.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#4
| |||
| |||
| Declaration Declare a 2-dimensional array as follows: Code: int[][] a2;
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#5
| |||
| |||
| Allocation As with all arrays, the new keyword must be used to allocate memory for an array. For example, Code: int[][] a2 = new int[10][5]; This actually allocates 6 objects: a one-dimensional array of 5 elements for each of the rows, and a one-dimensional array of ten elements, with each element pointing to the appropriate row array.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#6
| |||
| |||
| Can u explain this 2 dimensional array with the example? |
|
#7
| |||
| |||
| Sure… Often 2-dimensional arrays are processed with nested for loops. Notice in the following example how the rows are handled as separate objects. For example Code: int[][] a2 = new int[10][5];
// print array in rectangular form
for (int r=0; r<a2.length; r++) {
for (int c=0; c<a2[r].length; c++) {
System.out.print(" " + a2[r][c]);
}
System.out.println("");
}
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#8
| |||
| |||
| What’s the ragged array? |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Arrays in PHP | Sabari | PHP Programming | 133 | 12-02-2009 03:57 PM |
| Jagged Arrays in C# | vigneshgets | C# Programming | 4 | 09-30-2008 03:48 AM |
| Using arrays in stored procedures | it.wily | Database Support | 2 | 02-09-2008 09:18 AM |
| Split Arrays in ORACLE | Murali | Database Support | 2 | 08-22-2007 10:34 PM |
| Java:Tutorial - Arrays | pranky | Java Programming | 0 | 02-23-2007 11:54 PM |
Our Partners |