aspose file tools*
The moose likes Java in General and the fly likes multidimensional arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "multidimensional arrays" Watch "multidimensional arrays" New topic
Author

multidimensional arrays

ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
Hello,

I am trying to retrieve some information from a php file and the way I am getting the results is just like this:

432
333 99
17 19 22 31 85 76 51 32
9 17 16 5 13 12 14 13


so what I am doing in processing is call String lines[] = p.loadStrings(url); which gives me every line as an element of lines[] array. now what I should do is to use split function to put each element in every line in an array in order to use them later. so something along this way:

// before constructor
int totalPressed[];
int locationPressed[];
int areaOne[];
int areaTwo[];

// I am not even sure if I can do this.
int [][] metArray = {totalPressed, locationPressed, areaOne, areaTwo};




public void parsePHP(String url) {
String lines[] = p.loadStrings(url);
for (int i=0; i < lines.length; i++) {
// I need to find a way to
// push those values into those arrays.
// trying to declare below which doesn't work.
metArray[i][] = int(PApplet.split(lines[i]));
}
}


OF course this is not working
can you tell me what I am missing here?

thanks!
ilteris.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Without trying it, all that looks really close except that last line that does all the work.

You won't be able to split a String into an array of ints in one shot, but you can split it into an array of Strings, then manually build the array of ints.

Are you comfortable making an int from a String? If not, read up on the Integer class to find a method that will do the job.

Does that seem about right?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
Thanks for the quick response, yep your code made aa lot more sense, and here is what I came up with!



right now the problem is when I try to declare the arrays here:
int metArray[i][] = new int[strs.length];

since I don't have a second indexer, what should I be using here instead?
Am I on the right track?

thanks a lot
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If I'm following you, metArray needs to have one element in the first dimension for each line. So outside the first loop you can declare

int[][] metArray = new int[lines.length][];

The 2nd dimension size is unknown and will vary per line. What you find in each element in the first dimension is another array:

metArray[i] = new int[strs.length];

Now your line in the inner loop per token is good:

metArray[i][j] = Integer.parseInt(strs[j]);

The main thing to pick up is that metArray[i] is another array. Did that make sense?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multidimensional arrays