Arrays with vectors

Is it possible to make an array of vectors? I tried; PVector [ ] vtest = new PVector [20]; It lets me write it but gives me null messages when I execute.

1 Like
PVector[] vtest = new PVector[20];

void setup() {
  for ( int i = 0; i < 20; i++ ) vtest[i] = new PVector(1,1,1);

void draw() {}

works here


B/c it’s an array of object references, all of its indices are initialized w/ null when it’s created:

Thus we still need to assign a new PVector object reference for each of its indices:
vtest[0] = new PVector();


Dear kll, You’re a genius!!! Thanx so much.

1 Like