Results 1 to 8 of 8
Thread: Mulit dimensional Array
- 02-02-2009, 01:30 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
Mulit dimensional Array
Hi all,
I have a multi-dimensional array that i want to assign variables to certain parts however, this code is not working where have i gone wrong?
Java Code:String[][][] DetailsArray = new String[100][100][100]; DetailsArray[i][][] = surname; DetailsArray[][i][] = forename; DetailsArray[][i][] = age.toString();
Jon
- 02-02-2009, 01:35 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
In that you need to provide values for the other indexes as well. I.E.
Java Code:String[][][] DetailsArray = new String[100][100][100]; DetailsArray[i][x][y] = surname; DetailsArray[x][i][y] = forename; DetailsArray[x][i][y] = age.toString();
- 02-02-2009, 01:36 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
In multidimensional arrays you must define the initial size, that's the first array length.
- 02-02-2009, 01:38 PM #4
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
Hi but i want assign certain text to certain elements of the array so
Java Code:String[][][] DetailsArray = new String[100][100][100]; DetailsArray[i][i][i] = {surname, forename, age.toString()};
- 02-02-2009, 01:41 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
You have to use quotation for strings.
- 02-02-2009, 01:49 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
Well, what you're showing is a single three element array, whereas what you've declared is a three dimensional array. Think of a cube, as that is how it would lay out. The first [] signifies the top to bottom axis along the left hand side. The second [] signifies the left to right axis along the top, and the third [] signifies the front to back axis (again, along the top).
What exactly is it you want to store? Do you want to store a list of information consisting of three columns? I.E. a list of names combined with ages? If so, you need a two dimensional (not three) array with the second dimension being 3 (I.E. new String[100][3] to store 100 three column items) and the info above (for the sake of posterity assuming it is the fifth line in the list) would be either
Java Code:DetailsArray[4] = new String[] {surname, forename, age.toString()}; // or DetailsArray[4][0] = surname; DetailsArray[4][1] = forename; DetailsArray[4][2] = age.toString();
- 02-02-2009, 01:56 PM #7
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
Brilliant Thanks!!!
That is exactly what i need!!
Regards,
Jon
- 02-03-2009, 01:35 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
If you have solve the problem, please mark the thread solved. It's really helpful to us.
Similar Threads
-
assign a value to two dimensional array
By makpandian in forum New To JavaReplies: 4Last Post: 10-05-2011, 06:21 AM -
two-dimensional array
By kHim in forum New To JavaReplies: 4Last Post: 11-16-2008, 08:21 PM -
Multi dimensional Array
By Preethi in forum New To JavaReplies: 1Last Post: 07-09-2008, 04:34 PM -
How to initialize a two dimensional Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 09:48 PM -
Help with array multi-dimensional
By barney in forum New To JavaReplies: 1Last Post: 07-31-2007, 09:00 PM
Bookmarks