# Creating an array of arrays

**URL:** <https://discourse.processing.org/t/creating-an-array-of-arrays/6826>\
**Category:** Beginners\
**Created:** [December 22, 2018, 3:43pm UTC](https://discourse.processing.org/t/creating-an-array-of-arrays/6826 "2018-12-22T15:43:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanmars](https://avatars.discourse-cdn.com/v4/letter/e/f08c70/32.png) [@evanmars](https://discourse.processing.org/u/evanmars)\
**Post date:** [December 22, 2018, 3:43pm UTC](https://discourse.processing.org/t/creating-an-array-of-arrays/6826/1 "2018-12-22T15:43:41Z")

</div>

First time using Processing. Trying to make a temporary graphical interface for my Arduino project. Probably super simple question.  
How do I go about creating an array of arrays, then accessing the individual subelements?

I have a basic array myArray[] = {0,0,0,0,0};  
I want to be able to make more arrays of various sizes with myArray as the element.  
myArray[] firstArray = new myArray[3];  
myArray[] secondArray = new myArray[5];

firstArray[0][0] = 100;  
secondArray[1][2] = 37;

etc.

---

<div class="post-metadata">

**Author:** ![evanmars](https://avatars.discourse-cdn.com/v4/letter/e/f08c70/32.png) [@evanmars](https://discourse.processing.org/u/evanmars)\
**Post date:** [December 22, 2018, 4:09pm UTC](https://discourse.processing.org/t/creating-an-array-of-arrays/6826/2 "2018-12-22T16:09:02Z")

</div>

Made it an array of a class. That seems to do what I needed.

```auto

class theClass
{
  int a,b,c,d,e;
}

theClass[] firstArray = theClass[3];
theClass[] secondArray = theClass[5];

setup()
{
  firstArray[0].a = 100;
  secondArray[1].b = 37;
}

```

---

<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:** [December 22, 2018, 4:16pm UTC](https://discourse.processing.org/t/creating-an-array-of-arrays/6826/3 "2018-12-22T16:16:26Z")

</div>

`int[][]` 2d array example: 🤓

> [@Final array is being changed](https://discourse.processing.org/t/final-array-is-being-changed/1447/4):
>
> Some of my clone() examples I did a long time ago at the link below may help ya out: smile_cat[https://Forum.Processing.org/two/discussion/12044/how-do-i-copy-out-one-row-of-a-2d-array-into-a-1d-array](https://Forum.Processing.org/two/discussion/12044/how-do-i-copy-out-one-row-of-a-2d-array-into-a-1d-array) final int[][] stuff = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; final int[] myArray = stuff[2]; // it's an alias for stuff[2]. myArray[0] = 10; // thus it alters stuff[2] too! println(stuff[2][0]); // prints out 10. stuff[2] is also affected! final int[] myClone = stuff[2].clone(); // it's a clon…

> **[Array 2D / Examples](https://processing.org/examples/array2d.html)**
>
> Demonstrates the syntax for creating a two-dimensional (2D) array. Values in a 2D array are accessed through two index values. 2D arrays are useful for storing images. In this example, each dot is col…

---

<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:** [December 22, 2018, 4:30pm UTC](https://discourse.processing.org/t/creating-an-array-of-arrays/6826/4 "2018-12-22T16:30:54Z")

</div>

Some more 2D array sketches: 😇

> **[Rotating Cube - OpenProcessing](https://www.openprocessing.org/sketch/421281)**
>
> PeterCollingridge.AppSpot.com/3D-tutorial

[Studio.ProcessingTogether.com/sp/pad/export/ro.9ABG0RKl9D2Bx](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9ABG0RKl9D2Bx)

[Studio.ProcessingTogether.com/sp/pad/export/ro.9WgKFjA6WFscW](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9WgKFjA6WFscW)

---

<div class="post-metadata">

**Author:** ![evanmars](https://avatars.discourse-cdn.com/v4/letter/e/f08c70/32.png) [@evanmars](https://discourse.processing.org/u/evanmars)\
**Post date:** [December 22, 2018, 4:57pm UTC](https://discourse.processing.org/t/creating-an-array-of-arrays/6826/5 "2018-12-22T16:57:17Z")

</div>

Thanks. Must be too early in the morning here.  
I’ve been making multi-dimensional arrays like that for ever. Don’t know why I got tripped up.
