Java Collection Convert toSeperatedString(final Collection list)

Here you can find the source of toSeperatedString(final Collection list)

Description

to Seperated String

License

Open Source License

Declaration

public static <T> String toSeperatedString(final Collection<T> list) 

Method Source Code

//package com.java2s;

import java.util.Collection;

public class Main {
    public static <T> String toSeperatedString(final Collection<T> list) {
        final StringBuffer stringBuffer = new StringBuffer();
        for (final T element : list) {
            if (stringBuffer.length() != 0)
                stringBuffer.append(",");
            stringBuffer.append(element.toString());
        }/*from w  ww. j  a va  2 s.  c om*/
        return stringBuffer.toString();
    }

    public static <T> String toSeperatedString(final Collection<T> list, final String separator) {
        final StringBuffer stringBuffer = new StringBuffer();
        for (final T element : list) {
            if (stringBuffer.length() != 0)
                stringBuffer.append(separator);
            stringBuffer.append(element.toString());
        }
        return stringBuffer.toString();
    }
}

Related

  1. tooDelimitedString(final Collection coll, final String delim, final String prefix, final String suffix)
  2. toPrimitiveArray(final Collection values)
  3. toPrimitiveIntegerArray(Collection collection)
  4. toReadableString(Collection collection)
  5. toSeparatedString(Collection items, String separator)
  6. toSet(Collection c)
  7. toSingleton(Collection l)
  8. toSQLIn(Collection values)
  9. toStringBuilder( Collection collection, String delimiter)