Java - Write code to string Collection To String

Requirements

Write code to string Collection To String

Demo

//package com.book2s;
import java.util.*;

public class Main {
    public static String stringCollectionToString(
            final Collection<String> c, String seperator) {
        if (c == null || c.isEmpty()) {
            return "";
        }/*from  w  w w .  j  ava 2s .  c o  m*/

        if (seperator == null) {
            seperator = ", ";
        }

        final StringBuilder sb = new StringBuilder();
        for (final String value : c) {
            sb.append(value);
            sb.append(seperator);
        }
        sb.delete(sb.length() - seperator.length(), sb.length());
        return sb.toString();
    }
}

Related Exercise