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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With