# Adding array to array list

**URL:** <https://discourse.processing.org/t/adding-array-to-array-list/11006>\
**Category:** Coding Questions\
**Created:** [May 7, 2019, 6:05pm UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006 "2019-05-07T18:05:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 7, 2019, 6:05pm UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/1 "2019-05-07T18:05:09Z")

</div>

So Im new to processing and I’m trying to port p5 code.

This is the original p5 code

```auto
  this.init = function(){
      var theta = 360/sides;
       for (var i=0;i<sides;i++){
            var thetab = theta * i;
            var thetac = theta * i+theta;

            this.walls.push(true);
            this.edge.push([this.x+w/2*sin(thetab),this.y+w/2*cos(thetab),this.x+w/2*sin(thetac),this.y+w/2*cos(thetac)]);
            this.vertex.push([this.x+w/2*sin(thetac),this.y+w/2*cos(thetac)]);
            this.length = dist(this.x+w/2*sin(thetab),this.y+w/2*cos(thetab),this.x+w/2*sin(thetac),this.y+w/2*cos(thetac));
  }

```

Ive created arraylists to replace the arrays as such in the class outside of the constructor

```auto
ArrayList<Boolean> walls =new ArrayList<Boolean>();
ArrayList<Float[]> edge =new ArrayList<Float[]>();
ArrayList<Float> vertex =new ArrayList<Float>();

```

and am trying to add to them in an amended function like this.

```auto
  void init(){
      float theta = 360/sides;
       for (int i=0;i<sides;i++){
            float thetab = theta * i;
            float thetac = theta * i+theta;
            float []a = {x+w/2*sin(thetab),y+w/2*cos(thetab),x+w/2*sin(thetac),y+w/2*cos(thetac)};
            walls.add(true);
            edge.add( a);
            vertex.add(x+w/2*sin(thetac),y+w/2*cos(thetac));
            length = dist(x+w/2*sin(thetab),y+w/2*cos(thetab),x+w/2*sin(thetac),y+w/2*cos(thetac));
  }

```

however I get this error.

> The method add(int, Float) in the type ArrayList is not applicable for the arguments (float, float)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 7, 2019, 6:18pm UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/2 "2019-05-07T18:18:59Z")

</div>

There is a command vertex, therefore it’s confusing to name your ArrayList vertex

better would be vertexList.

You could say

before `setup()`:

`ArrayList<PVector> vertexList = new ArrayList();`

in `setup()`:

```
vertexList.add(new PVector(x+w/2*sin(thetac), 
  y+w/2*cos(theta*c)));

```

Chrisir

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 7, 2019, 6:21pm UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/3 "2019-05-07T18:21:53Z")

</div>

I will try that thanks, however its producing the error on the line before at edge.add

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 7, 2019, 7:21pm UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/4 "2019-05-07T19:21:47Z")

</div>

> [@paulgoux](#):
>
> its producing the error on the line before at edge.add

Do you mean `walls.add(true);` ?

replace

ArrayList walls =new ArrayList();

with

ArrayList walls =new ArrayList();

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 8, 2019, 12:14am UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/5 "2019-05-08T00:14:25Z")

</div>

No… you referenced vertex.add in your first reply, however on the line before vertex at edge.add, this is where im getting the error.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 8, 2019, 5:09am UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/6 "2019-05-08T05:09:40Z")

</div>

Can’t help you with that

---

<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:** [May 8, 2019, 5:18am UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/7 "2019-05-08T05:18:21Z")

</div>

@paulgoux , please bring your project ( or MCVE ) to  
[https://editor.p5js.org/](https://editor.p5js.org/)  
so we can see the whole thing ( your source? ).  
AND also can play.

* * *

and the JAVA code please post here again by  
pasting it into the

```auto
</> code tag

```

! and test if that what you posted is running ( besides that one error? )

so we easy can copy and try it in processing 3.5.3 JAVA mode  
to find your bug.

* * *

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 8, 2019, 9:50am UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/8 "2019-05-08T09:50:07Z")

</div>

Fixed its a simple error in this case. I’d created ArrayList\<Float[]\> edge =new ArrayList\<Float[]\>(); with a Float and not a float, so it then “a” needs to be Float a, and not float a.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 8, 2019, 3:52pm UTC](https://discourse.processing.org/t/adding-array-to-array-list/11006/11 "2019-05-08T15:52:35Z")

</div>

In case you were wondering this was my project.

[https://editor.p5js.org/paulgoux/sketches/NyWLGYBof](https://editor.p5js.org/paulgoux/sketches/NyWLGYBof)
