Alp Alp - 1 year ago 99
Java Question

Convert List<String> to delimited String

Possible Duplicate:

Java: convert List<String> to a join()d string

Having this:

List<String> elementNames = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6");

What is an elegant way to get String with a custom delimiter, like so:


Answer Source

If you don't mind using the StringUtils library provided by apache, you could do:

// Output is "a,b,c"
StringUtils.join(["a", "b", "c"], ',');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download