How to do an array of IntLists?

Whenever we create an array of a non-primitive datatype, that array is by default populated w/ null values.

Therefore we need to repopulate such array w/ instances of that datatype before using it:

static final int LISTS = 5;

final IntList[] lists = new IntList[LISTS];

{
  for (int i = 0; i < LISTS; lists[i++] = new IntList());
}

void setup() {
  printArray(lists);
  println();

  lists[3].append(8);

  println(lists[3]);
  println(lists[3].get(0));

  exit();
}
3 Likes