Java Array Concatenate concat(T[] objects)

Here you can find the source of concat(T[] objects)

Description

concat

License

Open Source License

Declaration

public static <T> String concat(T[] objects) 

Method Source Code

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

import java.util.List;

public class Main {
    public static <T> String concat(List<T> objects) {
        return concat(objects, 0);
    }/*from  www  .jav  a2  s.com*/

    public static <T> String concat(List<T> objects, int beginIndex) {
        return concat(objects, " ", beginIndex);
    }

    public static <T> String concat(List<T> objects, String separator) {
        return concat(objects, separator, 0);
    }

    public static <T> String concat(List<T> objects, String separator, int beginIndex) {
        return concat(objects.toArray(new Object[objects.size()]), separator, beginIndex);
    }

    public static <T> String concat(T[] objects) {
        return concat(objects, 0);
    }

    public static <T> String concat(T[] objects, int beginIndex) {
        return concat(objects, " ", beginIndex);
    }

    public static <T> String concat(T[] objects, String separator) {
        return concat(objects, separator, 0);
    }

    public static <T> String concat(T[] objects, String separator, int beginIndex) {
        if (objects.length == 0) {
            return "";
        }

        int index = -1;
        StringBuilder ret = new StringBuilder();

        for (Object s : objects) {
            index++;

            if (index >= beginIndex)
                if (s.toString().length() > 0) {
                    ret.append(separator).append(s);
                }
        }

        return ret.length() >= separator.length() ? ret.substring(separator.length()) : ret.toString();
    }
}

Related

  1. concat(T[] first, T[] second)
  2. concat(T[] first, T[] second)
  3. concat(T[] first, T[]... rest)
  4. concat(T[] head, T... tail)
  5. concat(T[] left, T[] right)
  6. concat(T[]... arrays)
  7. concat(T[]... tss)
  8. concatAll(byte[] a, byte[]... rest)
  9. concatAll(byte[] first, byte[]... rest)