# Adding str() array to a single string

**URL:** <https://discourse.processing.org/t/adding-str-array-to-a-single-string/7762>\
**Category:** Coding Questions\
**Created:** [January 23, 2019, 1:46pm UTC](https://discourse.processing.org/t/adding-str-array-to-a-single-string/7762 "2019-01-23T13:46:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hieronymus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hieronymus/32/2018_2.png) [@Hieronymus](https://discourse.processing.org/u/Hieronymus)\
**Post date:** [January 23, 2019, 1:46pm UTC](https://discourse.processing.org/t/adding-str-array-to-a-single-string/7762/1 "2019-01-23T13:46:01Z")

</div>

I’m having an array of individual strings.  
Basically, these are ascii codes converted to a string.

a = a counter  
str(char(txtArray[a]))

I could add all strings from the array to a single string ‘ab’ like the following line but this of course, is not practical:

tring ab = str(char(txtArray[1]))+ str(char(txtArray[2]))+ str(char(txtArray[3]));

println(ab);

I tried different methods, using append(), join() from the processing examples, but I just can’t wrap my head around it to make it work. The ‘append’ example here results in an error:

> “Type String of the last argument to method(object) doesn’t exactly match the vararg parameter type. Cast to Object to confirm the non-varargs invocation, or pass individual arguments of type object for a varargs invocation.”

How can I add individual strings from an array to a single string?

Here’s the code in my program:

```auto
  for(int a = 1; a < txtCount+1; a++){
     // StringList ab;
      text (char(txtArray[a]),(100+(12*a)),100); // writing to the screen.
     
     String ab = str(char(txtArray[1]))+ str(char(txtArray[2]))+ str(char(txtArray[3]));
           
     println(ab);  
      
     }

```

---

<div class="post-metadata">

**Author:** ![Hieronymus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hieronymus/32/2018_2.png) [@Hieronymus](https://discourse.processing.org/u/Hieronymus)\
**Post date:** [January 23, 2019, 3:05pm UTC](https://discourse.processing.org/t/adding-str-array-to-a-single-string/7762/2 "2019-01-23T15:05:17Z")

</div>

Thanks for looking. I found the solution by using join().

---

<div class="post-metadata">

**Author:** ![JackWitherell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jackwitherell/32/3361_2.png) [@JackWitherell](https://discourse.processing.org/u/JackWitherell)\
**Post date:** [January 23, 2019, 7:28pm UTC](https://discourse.processing.org/t/adding-str-array-to-a-single-string/7762/3 "2019-01-23T19:28:50Z")

</div>

Can you share your solution? It might be very useful for beginners/someone searching for solutions to their same problem online.

You didn’t explain what format txtArray is so I assumed it was ints, but if it was I would do something like:

```auto
String numArray(int[] input){
  String str="";
  for(int i=0; i<input.size(); i++){
    str+=char(input[i]);
  }
  return str;
}

```

which has pretty nasty time complexity. Your solution might be better.

---

<div class="post-metadata">

**Author:** ![Hieronymus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hieronymus/32/2018_2.png) [@Hieronymus](https://discourse.processing.org/u/Hieronymus)\
**Post date:** [January 24, 2019, 3:32pm UTC](https://discourse.processing.org/t/adding-str-array-to-a-single-string/7762/4 "2019-01-24T15:32:11Z")

</div>

Thanks Jack, much appreciated.  
Here’s the code I’m using now instead:

```auto
String[] chrtrs = new String[counter];
     
     for(int a = 0; a < counter; a++){

     chrtrs[a] = str(char(txtArray[a])); 
     } 
     
    String joinedChrtrs = join(chrtrs, ""); 

println(joinedChrtrs);

```

The string ‘joinedChrtrs’ contains all the characters selected now.

As a side note, I needed a rotation value (fraction of 2\*PI) converted to a string:

1. The fractions are converted to an integer.
2. txtArray is an array containing selected integers.
3. char converts the integers to ascii.
4. str converts the ascii to a string.
