Two Laptop Bag*
The moose likes Java in General and the fly likes How to initialize array bidimensional ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
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: 97

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: 97

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: 97

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: 97

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to initialize array bidimensional ?
 
Similar Threads
TicTacToe Game..
Bidimensional array to GUI?
initialize array bidimensional how 0 in construct
TicTacToe game
TicTacToe Game