Android Object Array Join join(Object[] array, String separator, int startIndex, int endIndex)

Here you can find the source of join(Object[] array, String separator, int startIndex, int endIndex)

Description

join

Declaration

public static String join(Object[] array, String separator,
            int startIndex, int endIndex) 

Method Source Code

//package com.java2s;

public class Main {
    public static String join(Object[] array, String separator) {
        if (array == null) {
            return null;
        }//ww w . j a v  a2  s  . co m
        return join(array, separator, 0, array.length);
    }

    public static String join(Object[] array, String separator,
            int startIndex, int endIndex) {
        if (array == null) {
            return null;
        }
        if (separator == null) {
            separator = "";
        }

        int noOfItems = (endIndex - startIndex);
        if (noOfItems <= 0) {
            return "";
        }

        StringBuilder buf = new StringBuilder(noOfItems * 16);

        for (int i = startIndex; i < endIndex; i++) {
            if (i > startIndex) {
                buf.append(separator);
            }
            if (array[i] != null) {
                buf.append(array[i]);
            }
        }
        return buf.toString();
    }
}

Related

  1. join(Object[] array, String separator)