aspose file tools
The moose likes Java in General and the fly likes How to initialize array bidimensional ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to initialize array bidimensional ?" Watch "How to initialize array bidimensional ?" New topic
Author

How to initialize array bidimensional ?

Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 94

How to initialize array bidimensional ?
Example:



I initialize in construct with value 0.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

You probably don't want the (int start[][]) in your constructor. Or if you do, at least give it a different name to your private field.

When you make a new array, you need to specify its dimensions, as inYou will find it's already full of zeros, because 0 is the default for an int.

If you wanted to put other numbers in, you could use Arrays.fill(). But you would have to loop over the arrays because in Java, there's no such thing as multi-dimensional arrays, only arrays of arrays.
Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 94

Hello Luigi!
thanks by response!
See:



In that case, the array has three dimensions ? Or is, can save three int numbers ?

Thanks! (:
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

It means it has 2 dimensions, the first of which consists of 3 int[] arrays, each containing 3 ints.

You should check out a good beginners' book like Head First Java.
Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 94

Luigi,

[] Are the dimensions?
The that is within, are the size ?
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Yes. And don't forget that the indexes start at 0.
Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 94

Very good!
More, and now, how to save numbers within of array ?
By example:


I save one number int in dimension TWO.
How ?
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to initialize array bidimensional ?
 
Similar Threads
TicTacToe Game
TicTacToe Game..
Bidimensional array to GUI?
TicTacToe game
initialize array bidimensional how 0 in construct