# Arrays with vectors

**URL:** <https://discourse.processing.org/t/arrays-with-vectors/17179>\
**Category:** Beginners\
**Created:** [January 19, 2020, 2:25am UTC](https://discourse.processing.org/t/arrays-with-vectors/17179 "2020-01-19T02:25:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asherzelig](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@asherzelig](https://discourse.processing.org/u/asherzelig)\
**Post date:** [January 19, 2020, 2:25am UTC](https://discourse.processing.org/t/arrays-with-vectors/17179/1 "2020-01-19T02:25:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 19, 2020, 3:01am UTC](https://discourse.processing.org/t/arrays-with-vectors/17179/2 "2020-01-19T03:01:06Z")

</div>

```auto
PVector[] vtest = new PVector[20];

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

void draw() {}

```

works here

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 19, 2020, 3:02am UTC](https://discourse.processing.org/t/arrays-with-vectors/17179/3 "2020-01-19T03:02:55Z")

</div>

B/c it’s an array of object references, all of its indices are initialized w/ `null` when it’s created:  
[Processing.org/reference/null.html](http://Processing.org/reference/null.html)

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

---

<div class="post-metadata">

**Author:** ![asherzelig](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@asherzelig](https://discourse.processing.org/u/asherzelig)\
**Post date:** [January 19, 2020, 5:33pm UTC](https://discourse.processing.org/t/arrays-with-vectors/17179/4 "2020-01-19T17:33:52Z")

</div>

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