Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-02-2009
Member
 
Join Date: Feb 2009
Posts: 40
How to implement MultiDimensional Array in JAVA

Hello Programming Gurus,

I am newbie to the Multidimensional Array topic in JAVA it has alway been difficult for me to understand so think here i will get some help.
So can anybody suggest how should i implement Multidimensional Array in JAVA, explain me with some example.

Regards,
Reply With Quote
  #2  
Old 28-02-2009
Member
 
Join Date: Jan 2009
Posts: 108
Re: How to implement MultiDimensional Array in JAVA

Here i will explain you with the small example on MultiDimensional Array in JAVA
please have a look at it.

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("");
}
Reply With Quote
  #3  
Old 28-02-2009
Member
 
Join Date: Jan 2009
Posts: 99
Re: How to implement MultiDimensional Array in JAVA

A multi-dimensional array of dimension n (i.e., an n-dimensional array or simply n-D array) is a collection of items which is accessed via n subscript expressions. For example, in a language that supports it, the tex2html_wrap_inline60030 element of the two-dimensional array x is accessed by writing x[i,j].

The Java programming language does not really support multi-dimensional arrays. It does, however, support arrays of arrays. In Java, a two-dimensional array x is really an array of one-dimensional arrays:

int[][] x = new int[3][5];

The expression x[i] selects the tex2html_wrap_inline57420 one-dimensional array; the expression x[i][j] selects the tex2html_wrap_inline59650 element from that array.

The built-in multi-dimensional arrays suffer the same indignities that simple one-dimensional arrays do: Array indices in each dimension range from zero to tex2html_wrap_inline59952, where length is the array length in the given dimension. There is no array assignment operator. The number of dimensions and the size of each dimension is fixed once the array has been allocated.
Reply With Quote
  #4  
Old 28-02-2009
Member
 
Join Date: Jan 2009
Posts: 163
Re: How to implement MultiDimensional Array in JAVA

The type-signatures and constructors of the multidimensional array use double brackets to distinguish them from ordinary arrays:

int [[,]] a = new int [[5, 5]] ;

float [[,,]] b = new float [[10, n, 20]] ;

int [[]] c = new int [[100]] ;

a, b and c are respectively 2-, 3- and one- dimensional arrays. Of course c is very similar in structure to the standard array d, created by

int [] d = new int [100] ;

c and d are not identical, though3.

Accessing individual elements of a multidimensional array goes through a subscripting operation involving single brackets

for(int i = 0 ; i < 4 ; i++)
a [i, i + 1] = i + c [i] ;

For reasons that will become clearer in later sections, this style of subscripting is called local subscripting. In the current sequential context, apart from the fact that a single pair of brackest may include several comma-separated subscripts, this kind of subscripting behaves just like ordinary Java array subscripting. Subscripts always start at zero, in the ordinary Java or C style (there is no Fortran-like lower bound).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to implement MultiDimensional Array in JAVA"
Thread Thread Starter Forum Replies Last Post
Implement Simple Database using BST in Java maxmidg412 Software Development 2 31-07-2011 03:22 AM
Multidimensional ArrayList in java Aaliya Seth Software Development 6 16-02-2011 01:03 AM
Multidimensional ArrayList in Java Navp Software Development 1 05-02-2011 12:43 AM
Implement the return type in java Captain Carrot Software Development 4 25-03-2010 01:34 PM
Implement Java tic tac toe SmokiN Software Development 3 29-06-2009 09:09 AM


All times are GMT +5.5. The time now is 03:51 PM.