Java Array Concatenate concatenate(Object[] collection)

Here you can find the source of concatenate(Object[] collection)

Description

concatenate

License

Open Source License

Declaration

public static String concatenate(Object[] 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 String concatenate(Object[] collection) {
        return concatenate(Arrays.asList(collection), ",");
    }//  ww  w .j  a va 2 s .  co m

    public static String concatenate(Object[] collection, String separator) {
        return concatenate(Arrays.asList(collection), separator);
    }

    public static String concatenate(Object[] collection, String separator, boolean... keepLastDot) {
        return concatenate(Arrays.asList(collection), separator, keepLastDot);
    }

    public static String concatenate(Collection c) {
        return concatenate(c, ",");
    }

    public static String concatenate(Collection c, String separator, boolean... keepLastDot) {
        StringBuffer sb = new StringBuffer();
        for (Object o : c)
            sb.append(o.toString()).append(separator);

        if (!c.isEmpty() && keepLastDot.length == 0) // remove extra separator at the end
            sb.setLength(sb.length() - separator.length());

        return sb.toString();
    }
}

Related

  1. concatenate(int[]... arrays)
  2. concatenate(Object[] array)
  3. concatenate(Object[] array)
  4. concatenate(Object[] array)
  5. concatenate(Object[] array)
  6. concatenate(String[] args)
  7. concatenate(String[] strings, String sep)
  8. concatenate(T[] first, T[] second)
  9. concatenate2Arrays(T[] array1, T... array2)