jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Array" Watch "Array" New topic


balajee annamalai
Ranch Hand

Joined: May 09, 2007
Posts: 31
Can someone please expain me about single and multi dimension array by a pictorial example?
Ahmed Kishk

Joined: Mar 05, 2008
Posts: 2
1-Arrays are objects in Java that store multiple variables of the same type

2-Arrays can hold either primitives or object references

3- To Constructing One-Dimensional Arrays
int [] myArray;
myArray = new int[4];
you can assign four int values in this array "myArray"

4- To Constructing Two-Dimensional Arrays
int [][] myDimArray;
myDimArray= new int[4][4];

you can assign sixteen int values in this array and refer to them
with two indexs
this is a practical sample that generats random number and store it in the array and then print them again
Random generator = new Random();
int [][] array = new int[4][4];
for(int i = 0 ; i < 4; i++)
for(int j = 0; j <4;j++)
array[i][j] = generator.nextInt(16);

for(int i = 0 ; i < 4; i++)
for(int j = 0; j <4;j++)
marc weber

Joined: Aug 31, 2004
Posts: 11343

In Java, a "multi-dimensional" array is really just a single-dimension array whose elements are other single-dimension arrays.

The shorthand syntax provides a nice diagram...

Here you can see that i references an array containing 2 elements. The first element (i[0]) is an array containing 3 ints, and the second element (i[1]) is an array containing 4 ints.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link: http://aspose.com/file-tools
subject: Array
It's not a secret anymore!