Java Array Join join(final T[] collection)

Here you can find the source of join(final T[] collection)

Description

join

License

Open Source License

Declaration

public static <T> String join(final T[] collection) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.Collection;

public class Main {

    public static <T> String join(final T[] collection) {
        return join(Arrays.asList(collection));
    }/*from ww  w  .j av a  2 s  .  c  om*/

    public static <T> String join(final T[] collection, final String separator) {
        return join(Arrays.asList(collection), separator);
    }

    public static String join(final Collection<?> collection) {
        return join(collection, ", ");
    }

    public static String join(final Collection<?> collection, final String joinString) {
        if (collection != null) {
            final StringBuilder str = new StringBuilder();

            int i = 0;
            final int max = collection.size();
            for (final Object object : collection) {
                str.append(object.toString());

                if (++i < max) {
                    str.append(joinString);
                }
            }

            return str.toString();
        } else {
            return null;
        }
    }
}

Related

  1. join(final String[] in, final String sep)
  2. join(final String[] strings)
  3. join(final String[] strings, final String joinString)
  4. join(final String[] values, final String delimiter)
  5. join(final T[] array, final char c)
  6. join(int[] array, String separator)
  7. join(int[] follows)
  8. join(long[] a, long[] b)
  9. join(long[] array, String delim)