join(int[], separator)

Hello, I created this methood because I needed it and It wasn't included in processing and am sharing it for people who may want it. I am also open to suggestions. It is a different version of join() (http://processing.org/reference/join_.html).

String join(int[] val, String sep) {
  String string = "";
  for(int i = 0; i < val.length; i++) {
    if(i != 0) {
      string += sep;
    }
    string += "" + val[i];
  }
  return string;
}

Answers

  • Answer ✓

    How about this 1? ;;)

    static final String joinIntArray(int[] arr, char sep) {
      return join(str(arr), sep);
    }
    
    static final String joinIntArray(int[] arr, String sep) {
      return join(str(arr), sep);
    }
    
  • KaiGrid, read up on StringBuffer / StringBuilder.

  • And no need for the "" + val[i] trick, as += already converts the int to string.

Sign In or Register to comment.