This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# 6x6x6x6x6 array representation

Eric Racin
Ranch Hand
Posts: 39
I need this multi-dimensional array (6x6x6x6x6 = 7776 elements):
This is a portion of the data:
0 0 0 0 0 445
91 151 179 180 155 544
224 368 437 435 370 673

How do I know where to put the brackets?
public int iArray[][][][][] = ?
Do I do this?
{{{{{{ 0, 0, 0, 0, 0, 445}
{ 91, 151, 179, 180, 155, 544}
{224, 368, 437, 435, 370, 673}

Kevin Workman
Ranch Hand
Posts: 151
• 1
Good lord why would you want to use brackets to instantiate a 6x6x6x6x6 array? I would actually argue that using an array of that size is a sure sign of a bad design, but that's another point.

Why don't you just do something like this:

Then loop through to set each index?

But, again, there is probably a much better way to go about doing this without using such a ridiculous array.

PS- Are you sure you don't just need a 2-dimensional array?

Darryl Burke
Bartender
Posts: 5149
11
It helps to remember that in Java, a multi dimensional array is an array of arrays.

So an int[] is an array of ints
an int[][] is an array of int[]
...
an int[][][][][] is an array of int[][][][]

I agree with Kevin that having to use a 5 dimensional array is likely an outcome of bad design, and there is probably a better way of doing whatever it is you are doing. Would you like to share that? the problem, not any solution that has come to your mind.

Eric Racin
Ranch Hand
Posts: 39
Point well taken. The real problem is that are production Tomcat Servlet
will not read anything from a file (while the test Server works fine!)
This is a brute force attempt to have the data within the Servlet itself, but
I am confused as to where to put the brackets.

(The 6x6x6x6x6 array results from the possible permutation of choices from the user:
5 fields with 6 choices per field)

Rob Spoor
Sheriff
Posts: 20709
68
Let's focus on the main problem - why you can't read from the file. Are you reading the file from the right location? Are you using ServletContext.getRealPath?

Eric Racin
Ranch Hand
Posts: 39
getRealPath() is a good idea. However, from my research it looks like
it will return \index.html.
getPathTranslated() will probably return something like
\Tomcat\webapps\Root\index.html

The needed file was opened successfully at
\Tomcat\bin on one Server.

On the problem Server I also placed it in
\Tomcat4.1\webapps\ROOT and
\Tomcat4.1\webapps\carbonapp3\WEB-INF\classes

I guess I could sprinkle it throughout the directories but I feel like I
am on a wild goose chase. The permissions have been checked as
well as the Server's security model. That is why I was giving up
and placing the array within the Servlet.

Wouter Oet
Saloon Keeper
Posts: 2700