join object to string - Android java.lang

Android examples for java.lang:String Join

Description

join object to string

Demo Code


public class Main{

    public static String join(Object[] objArr, String str) {
        return objArr == null ? null : join(objArr, str, 0, objArr.length);
    }/*from ww  w  . j  a v  a 2  s.co m*/
    public static String join(Object[] objArr, String str, int i, int i2) {
        if (objArr == null) {
            return null;
        }
        if (str == null) {
            str = "";
        }
        int i3 = i2 - i;
        if (i3 <= 0) {
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder(
                ((objArr[i] == null ? 128 : objArr[i].toString().length()) + str
                        .length()) * i3);
        for (int i4 = i; i4 < i2; i4++) {
            if (i4 > i) {
                stringBuilder.append(str);
            }
            if (objArr[i4] != null) {
                stringBuilder.append(objArr[i4]);
            }
        }
        return stringBuilder.toString();
    }

}

Related Tutorials