user697911 user697911 - 1 year ago 73
Java Question

Print comma delimited items from a List

List<String> strs = new ArrayList<String>();

for(String str : strs) {
System.out.println(str + ",");

This will print as "a, b, c,". I can do a substring() extraction to remove the trailing comma, but it seems awkward. How to avoid the last comma in the iteration?

Answer Source

Another solution:

String separator = "";
for(String str : strs) {
    separator = ",";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download