We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have some programing experience. Lately I have used Ruby. In Ruby it is possible to "stack" arrays. I am trying to do a similar thing in processing and I can't figure out how. A "stacked" array in an array within an array. Here is an example.
array[1, 4,[6,5,0],3,7] array[1] returns 1 array[2] returns 4 array[3,1] returns 6 array[3,2] returns 5 etc.
As I mentioned this works in Ruby, and I would like to do this in processing. Any help?
Answers
We can't do that in a direct form w/ Java's arrays! B/c all elements within 1 gotta be of the same data type. 8-X
Let's say we wish to store
byte
type values. We can't have bothbyte
&byte[]
inside the same array! #-oHowever, rather than having a mix of
byte
&byte[]
elements, let's make all of thembyte[]
! =:)Therefore, a former
byte
becomes abyte[]
of length = 1 element now! *-:)And we end up w/ a 2D
byte[][]
array instead of 1D! :ar!Thanks, just a few questions, Final byte [][] stacks = {{1},{2,1}}; Is how I define the array right? If I wanted to call a specific element I could say byte[2][1] right?
To declare an array variable we use
data-type[]
. Replace data-type w/ the chosen type.There are a couple of ways to instantiate an array object. I've used
{}
in my example above.http://processing.org/reference/Array.html
http://processing.org/reference/arrayaccess.html
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
thanks