# Thread: processing a 3 dimensional array

1. Member
Join Date
Jun 2011
Posts
9
Rep Power
0

## processing a 3 dimensional array

how would you process a 3 dimensional array in java? Example please?

2. Originally Posted by heycoa
how would you process a 3 dimensional array in java? Example please?
It seems to me that you are asking a very vague and overly-general question, perhaps too vague to be answerable. You may wish to give more details and ask a more specific question. What exactly are you having problems with? What do you mean by "process"? Array of what? Also we prefer to work with your examples/attempts. A good rule of thumb is to try to put as much effort into asking your question as you'd want someone to put in trying to answer it.

Much luck.
Last edited by Fubarable; 07-28-2011 at 05:59 AM.

3. The best thing to do is write a program which sums up a 3 dimensional array of integers. How would you process a single dimension array? How about a 2 dimensional array? Is there anything similar?

4. Originally Posted by heycoa
how would you process a 3 dimensional array
I wouldn't. I avoid 2D arrays as much as possible. There is no way I would touch a 3D array. Think redesign.

5. I agree entirely with what junky said. I try to always avoid 2d arrays, they should only be used if you cannot think of any other way(IMO), 3d arrays would quickly get too complex to comfortably manage any serious tasks.

6. OK, I'm curious -- why avoid multi-dimensional arrays, especially in places where they well model the problem domain? For instance, if you are creating a model for Conway's Game of Life, wouldn't you do this using a 2-dimensional array of game-cell? A sudoku grid or tic-tac-toe grid are other examples that come to mind. I've also had good success using 2-D arrays of Strings to represent the texts held by calculator buttons... e.g.,

Java Code:
```public class MyCalc {
//...
private static final String[][] CALC_STRINGS = {
{"7", "8", "9", "+"},
{"4", "5", "6", "-"},
{"1", "2", "3", "+"},
{"0", ".", "/", "="}};
//...

public MyCalc() {
//...
btnPanel.setLayout(new GridLayout(0, CALC_STRINGS[0].length, 2, 2));
for (int i = 0; i < CALC_STRINGS.length; i++) {
for (int j = 0; j < CALC_STRINGS[i].length; j++) {
JButton btn = new JButton(CALC_STRINGS[i][j]);
if ("1234567890.".contains(CALC_STRINGS[i][j])) {
} else {
}
//...
}
}
//...```
Since the array mirrors the physical reality, it makes it much easier to debug or modify.

I'm sort of sorry for veering off the original intent of the original post, but the original poster seems to have lost interest in this thread as he has not yet replied to a single request for clarification of his problem.
Last edited by Fubarable; 07-28-2011 at 07:00 AM.

7. avoid as much as possible != will not use ;)

8. I'm not saying there is never a need for two dimensional arrays, but perhaps the fact that I'm still not amazingly experienced leads me to avoid them if possible. Your snippet does make sense, but it could be equally represented by a single dimension array, couldn't it?

Can you think of any great uses of 3d arrays? I feel like they would mostly just be used as exercises to help someone understand in depth how multi dimensional arrays work.

Sudoku solvers, and conways game of life are topics I'm unfamiliar with(been meaning to read jos's post on sudoku solvers but haven't gotten to it yet), and I won't dispute that 2 d arrays are invaluable in those situations.
Last edited by sunde887; 07-28-2011 at 07:13 AM.

9. Originally Posted by Fubarable
OK, I'm curious -- why avoid multi-dimensional arrays, especially in places where they well model the problem domain? For instance, if you are creating a model for Conway's Game of Life
Conway's GOL is much better off by not using two dimensional arrays but use lists of living cells instead. That way you only have to process the 'interesting' cells. 2D arrays are so Fortranesque ;-)

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•