Java Collection to String asString(Collection c, String separator)

Here you can find the source of asString(Collection c, String separator)

Description

as String

License

Open Source License

Declaration

public static String asString(Collection c, String separator) 

Method Source Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static String asString(Collection c, String separator) {
        if (c == null) {
            return "";
        }//from www  .j  av  a 2s  .  c om
        StringBuilder result = new StringBuilder(256);
        boolean needSeparator = false;
        for (Object o : c) {
            if (o == null) {
                continue;
            }
            String str = o.toString().trim();
            if (str.equals("")) {
                continue;
            }
            if (needSeparator) {
                result.append(separator);
            }
            result.append(str);
            needSeparator = true;
        }
        return result.toString();
    }
}

Related

  1. asString(Collection collection)
  2. asStringArr(Collection collection)
  3. asStringArray(Collection coll)
  4. asStringArray(Collection collection)