We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
Been banging my head over this ( new to processing ), cant quite seem to figure it out.. I've made an array list and I'm trying to populate a bunch of arrays in setup() with unique id's using a "for" loop, just can't seem to work out the syntax any help would be appreciated. Cheers! .. Snippet of a larger code below..
int res_x = 10; // This will eventually be a dynamic number
ArrayList<Array> SX;
void setup(){
SX = new ArrayList<Array>();
// here I want to iterate through and create a bunch of arrays and add them to my array list!
for (int i = 0; i < res_x; 1++){
int[] vert_x+"i" = new int[res_x]; // this is the line I'am having trouble with!
SX.add(vert_x+"i");
}
println(SX.size());
}
Any help would be awesome!
Answers
Do you have a class called Array? Probably not. Think about how you declare an array. You give it a type and use the [] syntax, like this:
int[] array = new int[10];
So to create an ArrayList that holds an array, you simply pass the type of the array into the <> part, which is called a generic type argument. Like this:
ArrayList<int[]> list = new ArrayList<int[]>();
Now to add an array to your ArrayList, you just combine the ideas:
referencing those is a case of
(oops, hit accept instead of edit...)
how would you create an array that holds and array list?
An array of ArrayLists:
You could also make an ArrayList of arrays of ArrayLists...
or an array of ArrayLists of arrays of Arraylists of arrays...
However at a certain point retrieving and updating data gets so complex and painful to write that you should consider an easier interface -- for example, using Table, or creating a custom class.