Adding str() array to a single string

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

a = a counter

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]));


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:

  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]));
1 Like

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

1 Like

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:

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

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


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

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

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


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.