Is there a Java / Android equivalent to the iOS function "componentsJoinedByString" for an NSArray?

android, arrays, ios, iphone, java

Solution

Use `TextUtils.join()`:

String myArray[] = new String[]{ "A", "B", "C", "D" };
String myString = TextUtils.join(", ", myArray);

There is also a version (same syntax) that takes an `Iterable` if you need to join something like an `ArrayList`.

Problem

Is there anything like this in Java? ``` NSString *myString = [myArray componentsJoinedByString:@", "]; ``` Here's an example of some output: ``` A, B, C, D ``` If not, what's the best way to accomplish this?

Original source