Thursday, August 25, 2016

Sequence of characters separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix


If you have an array of Strings, say ["9", "30", "0"], and you wish to convert it to a String "[9, 30, 0]", do:

StringJoiner sj = new StringJoiner(",", "[", "]");
Arrays.asList(myArray).forEach(p -> sj.add(p));
sj.toString();

More about StringJoiner:
https://docs.oracle.com/javase/8/docs/api/java/util/StringJoiner.html