join varargs to array - Android java.lang

Android examples for java.lang:array join

Description

join varargs to array

Demo Code


//package com.java2s;

public class Main {
    public static String join(int... array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i]);//from w  w  w. j av  a2 s .c  om
            if (i < array.length - 1)
                sb.append(',');
        }

        return sb.toString();
    }

    public static String join(long... array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i]);
            if (i < array.length - 1)
                sb.append(',');
        }

        return sb.toString();
    }
}

Related Tutorials