Given:
String[] a = new String[] { "Hello", "World", "!" };
Then as an alternative to coobird's answer, where the glue is ", ":
Arrays.asList(a).toString().replaceAll("^\\[|\\]$", "")
Or to concatenate with a different string, such as " & ".
Arrays.asList(a).toString().replaceAll(", ", " & ").replaceAll("^\\[|\\]$", "")
However... this one ONLY works if you know that the values in the array or list DO NOT contain the character string ", ".
No comments:
Post a Comment