# How to text array

**URL:** <https://discourse.processing.org/t/how-to-text-array/30192>\
**Category:** Coding Questions\
**Created:** [May 20, 2021, 2:47pm UTC](https://discourse.processing.org/t/how-to-text-array/30192 "2021-05-20T14:47:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 2:47pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/1 "2021-05-20T14:47:11Z")

</div>

hi all

how to text array elements i have try but i could not do it looks random and wrong code

any help

thanks in advance

```auto

void setup () { 
size ( 800 , 800 );  

}
void draw () { 

  fill(0);
int[] x = { 
  50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
676, 61, 83, 69, 71, 50, 29, 31, 17, 39
};

fill(0);

for (int i = 0; i < x.length; i++) {

  
  textSize(20);
  text(x[i],x[i]*12,i*10);
}
}

```

---

<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 20, 2021, 2:48pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/2 "2021-05-20T14:48:54Z")

</div>

Have you tried str() should convert strings or floats.

Weirdly this isnt required for println as it auto converts.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 2:51pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/3 "2021-05-20T14:51:22Z")

</div>

> [@paulgoux](#):
>
> println as it auto converts.

i want to text it on screen not with println

---

<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 20, 2021, 2:54pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/4 "2021-05-20T14:54:12Z")

</div>

Not a problem use str()

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 2:55pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/5 "2021-05-20T14:55:20Z")

</div>

give me hint how to use str()

---

<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 20, 2021, 2:57pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/6 "2021-05-20T14:57:51Z")

</div>

[https://processing.org/reference/strconvert\_.html](https://processing.org/reference/strconvert_.html)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 3:12pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/7 "2021-05-20T15:12:05Z")

</div>

look what i want this array contains few elements i text all of them but if the more than screen width they out of boarder i want to text the elements as the are in the array

```auto

void setup () { 
size ( 800 , 800 );  

}
void draw () { 

  fill(0);
int[] x = { 
  50, 61, 83, 69, 71, 50, 
 

};

fill(0);

for (int i = 0; i < x.length; i++) {

  
  textSize(20);
  text(x[i],i*44,55);
}
}

```

---

<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 20, 2021, 3:28pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/8 "2021-05-20T15:28:07Z")

</div>

didnt understand much of that. Can you clarify please.

---

<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 20, 2021, 3:31pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/9 "2021-05-20T15:31:43Z")

</div>

what are you trying to achieve your code already displays the values in the array.

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e6872c52aeed3d335dc616655133ed3bb14b1aaa.png)

`if(i*44<width)text(x[i],i*44,55);`

this will limit the displayed number to only those that fit in the window, note the array values are still being iterated though.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 3:36pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/10 "2021-05-20T15:36:34Z")

</div>

> [@paulgoux](#):
>
> didnt understand much of that. Can you clarify please.

what i need incited of printing array elements on consuls

> [@paulgoux](#):
>
> what are you trying to achieve your code already displays the values in the array.

this is just 6 elements texting them no issue but what if the array contains lets say 200 elements how to text them

---

<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 20, 2021, 3:39pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/11 "2021-05-20T15:39:10Z")

</div>

```auto
void setup () { 
size ( 800 , 800 );  

}
void draw () { 

  fill(0);
int[][] x = { 
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{50, 61, 83, 69, 71, 50, 29, 31, 17, 39},
{676, 61, 83, 69, 71, 50, 29, 31, 17, 39}
};

fill(0);

for (int i = 0; i < x.length; i++) {
  for (int j = 0; j < x[0].length; j++) {
  
  textSize(20);
  text(x[i][j],50*j,i*20);
}
}}

```

---

<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 20, 2021, 3:44pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/12 "2021-05-20T15:44:05Z")

</div>

```auto
void setup () { 
size ( 800 , 800 );  

}
void draw () { 

  fill(0);
int[] x = { 
  50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
 50, 61, 83, 69, 71, 50, 29, 31, 17, 39,
676, 61, 83, 69, 71, 50, 29, 31, 17, 39
};

fill(0);
int row = 0;
float spacing = 25;
float xx = 0;
for (int i = 0; i < x.length; i++) {
  xx += spacing;
  textSize(20);
  if(xx>width){
    xx = 0;
    row++;
  }
  println(row);
  text(x[i],xx,50+row*20);
}
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 3:47pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/13 "2021-05-20T15:47:00Z")

</div>

[paulgoux](https://discourse.processing.org/u/paulgoux)

thanks a a lot that is what i want but i do have other question but let my prepare how to ask it thanks again for the second way

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 4:19pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/14 "2021-05-20T16:19:37Z")

</div>

@paulgoux  
thanks for you the code is part of timing measurement like this but may i ask some other thing when i apply my all stuff

![free](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ad07e0a8775940cfc256c8b67a15c79b7f73a074.png)

---

<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 20, 2021, 4:22pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/15 "2021-05-20T16:22:33Z")

</div>

Sure what do you need?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 4:25pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/16 "2021-05-20T16:25:52Z")

</div>

i am not sure yet did not fished and i am not stuck for now

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 20, 2021, 5:49pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/17 "2021-05-20T17:49:07Z")

</div>

@paulgoux  
explain this line

```auto
 for (int j = 0; j < x[0].length; j++) {

```

---

<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 20, 2021, 6:01pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/18 "2021-05-20T18:01:17Z")

</div>

Your iterating through a double array so you need the length of the internal array.

The code however is assuming that all internal arrays are the same size, else use `x[i].length`

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [May 20, 2021, 6:23pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/19 "2021-05-20T18:23:40Z")

</div>

Using @paulgoux suggestion for using String, I wonder if this too is of use to your question. Then you don’t need to use the array and for loop…  
🤔

//////////////////////////////////////////////

```auto
void setup () { 
  size (800, 800);
}
void draw () { 

  fill(0);

  String strg1 = "50, 61, 83, 69, 71, 50, 29, 31, 17, 39, 50, 61, 83, 69, 71, 50, 29, 31, 17, 39, 50, 61, 83, 69, 71, 50, 29, 31, 17, 39, 50, 61, 83, 69, 71, 50, 29, 31, 17, 39"; // I did not include all of your numbers, this is just a text to see if solves the question

  textSize(20);
  text(strg1, 20, 40, 750, 750);
}

```

---

<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 20, 2021, 7:58pm UTC](https://discourse.processing.org/t/how-to-text-array/30192/20 "2021-05-20T19:58:57Z")

</div>

> [@jafal](#):
>
> array

this might be interesting [https://www.processing.org/tutorials/data/](https://www.processing.org/tutorials/data/)

it shows how to load and display _Tabular Data_

[Next page](https://discourse.processing.org/t/how-to-text-array/30192.md?page=2)
