This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Loading 2-dimensional array with values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loading 2-dimensional array with values" Watch "Loading 2-dimensional array with values" New topic

Loading 2-dimensional array with values

Steve Schowiak

Joined: Oct 21, 2002
Posts: 20
After creating a new array object, I want to load it with constant values. Being a COBOL programmer, I would make a sequential file with the values, and read them into the array. But I don't want to do this with JAVA. My program will eventually be an applet and won't be able to read in a sequential file (it's a DOS app now).
The answer is putting all the data in a class, and setting up the array in there. Now, I'm stuck with writing 625 lines of code that looks like:
MyArray[1][1] = 31;
MyArray[1][2] = 26;
MyArray[24][24] = 21;
There's got to be a more practical way of loading this array with constants other than this way or reading from external files.
But what is it?
Thanks. :roll:

I am not insane. The voices in my head told me so.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
int[][] foo = { { 1, 2, 3 }, { 4,5, 6} };
James Chegwidden
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Also, remember subscripts start at 0
so array[0][0] etc.

Author and Instructor, my book
I agree. Here's the link:
subject: Loading 2-dimensional array with values
It's not a secret anymore!