Java Collection Join join(Collection things, String delim)

Here you can find the source of join(Collection things, String delim)

Description

join

License

Open Source License

Declaration

public static <T> String join(Collection<T> things, String delim) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.List;

public class Main {
    public static <T> String join(Collection<T> things, String delim) {
        return join(things.toArray(), delim);
    }/*from w  w  w.j  a  v  a 2  s.c o m*/

    public static <T> String join(T[] things, String delim) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (T t : things) {
            if (first)
                first = false;
            else
                sb.append(delim);
            sb.append(t);
        }
        return sb.toString();
    }

    public static String toString(List<?> arr) {
        return toString(arr, true);
    }

    public static String toString(List<?> arr, boolean square) {
        return toString(arr.toArray(), square);
    }

    public static String toString(Object[] arr) {
        return toString(arr, true);
    }

    public static String toString(Object[] arr, boolean square) {
        if (arr == null)
            return "null";
        StringBuffer sb = new StringBuffer();
        if (square) {
            sb.append("[");
        } else {
            sb.append("(");
        }
        for (int i = 0; i < arr.length; ++i) {//Object o : arr ) {
            if (i > 0)
                sb.append(",");
            if (arr[i] == null) {
                sb.append("null");
            } else {
                sb.append(arr[i].toString());
            }
        }
        if (square) {
            sb.append("]");
        } else {
            sb.append(")");
        }

        return sb.toString();
    }
}

Related

  1. join(Collection collection, String joinString)
  2. join(Collection collections, String separator)
  3. join(Collection list, final String separator)
  4. join(Collection list, String delimiter)
  5. join(Collection s, String delimiter)
  6. join(Collection values, String join)
  7. join(final char _separator, final boolean _quotes, final Collection _list, final String _emptyString)
  8. join(final Collection collection, String delimiter)
  9. join(final Collection e, final String s)