We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
2-D Arrays (Read 673 times)
2-D Arrays
Oct 27th, 2007, 10:12pm
 
I'm having trouble with 2-D array manipulation. Suppose I want to do the following:

 int[][] test = {{1,2},{3,4}};
 test = append(test, {5,6});

That doesn't work. So instead I try:

 int[][] test = {{1,2},{3,4}};
 test = expand(test, 3);
 test[2][0] = 5;
 test[2][1] = 6;

That doesn't work either. Basically, it seems like none of the Processing array functions work on 2-D arrays. I'd like to not have to create a new integer array any time I want to append or contract in 2-D, how can I do so?

Thanks.
Re: 2-D Arrays
Reply #1 - Oct 27th, 2007, 10:17pm
 
Code:
  int[][] test = {{1,2},{3,4}};
test = append(test, {5,6});


Should be:

Code:
   int[][] test = {{1,2},{3,4}};
test = append(test, new int[]{5,6});


Re: 2-D Arrays
Reply #2 - Oct 27th, 2007, 10:27pm
 
Thanks, but that doesn't work either.
Re: 2-D Arrays
Reply #3 - Oct 27th, 2007, 11:23pm
 
Ah, you need a cast, to tell it that the result is a 2D array.

Code:
  int[][] test = {{1,2},{3,4}};
test = (int[][])append(test, new int[]{5,6});
Re: 2-D Arrays
Reply #4 - Oct 27th, 2007, 11:39pm
 
Interesting. Awkward, but it makes sense. Thank you.
Page Index Toggle Pages: 1