Java Collection to String toString(String[] collection, char separator)

Here you can find the source of toString(String[] collection, char separator)

Description

GWT-ified CollectionUtils.toString.

License

LGPL

Declaration


public static String toString(String[] collection, char separator) 

Method Source Code

//package com.java2s;
// Metawidget (licensed under LGPL)

import java.util.Collection;

public class Main {
    /**/*w ww .ja v a2s .  c om*/
     * GWT-ified <code>CollectionUtils.toString</code>.
     * <p>
     * This version does not use regular expressions.
     */

    public static String toString(String[] collection, char separator) {

        if (collection == null) {
            return "";
        }

        StringBuilder builder = new StringBuilder();

        for (String item : collection) {
            if (builder.length() > 0) {
                builder.append(separator);
            }

            builder.append(item);
        }

        return builder.toString();
    }

    /**
     * GWT-ified <code>CollectionUtils.toString</code>.
     * <p>
     * This version does not use regular expressions.
     */

    public static String toString(Collection<?> collection, char separator) {

        if (collection == null) {
            return "";
        }

        StringBuilder builder = new StringBuilder();

        for (Object item : collection) {
            if (builder.length() > 0) {
                builder.append(separator);
            }

            builder.append(item);
        }

        return builder.toString();
    }
}

Related

  1. toString(final Collection collection, final String separator)
  2. toString(final Collection objs)
  3. toString(final Collection values)
  4. toString(final Collection list, final String delimiter)
  5. toString(final Collection c)
  6. toStrings(Collection vals)
  7. toStrings(Collection c)
  8. toStrings(Collection objects)
  9. toStrings(final Collection stringCollection)