Results 1 to 8 of 8
Thread: Mulit dimensional Array
- 02-02-2009, 12: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?
regards,Java Code:String[][][] DetailsArray = new String[100][100][100]; DetailsArray[i][][] = surname; DetailsArray[][i][] = forename; DetailsArray[][i][] = age.toString();
Jon
- 02-02-2009, 12:35 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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, 12:36 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In multidimensional arrays you must define the initial size, that's the first array length.
- 02-02-2009, 12: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
Could i do this?Java Code:String[][][] DetailsArray = new String[100][100][100]; DetailsArray[i][i][i] = {surname, forename, age.toString()};
- 02-02-2009, 12:41 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You have to use quotation for strings.
- 02-02-2009, 12:49 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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
Assuming surname and forname are variables.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, 12: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, 12:35 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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, 05:21 AM -
two-dimensional array
By kHim in forum New To JavaReplies: 4Last Post: 11-16-2008, 07:21 PM -
Multi dimensional Array
By Preethi in forum New To JavaReplies: 1Last Post: 07-09-2008, 03:34 PM -
How to initialize a two dimensional Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:48 PM -
Help with array multi-dimensional
By barney in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks