Join int array into string with separator String - Android java.lang

Android examples for java.lang:String Join

Description

Join int array into string with separator String

Demo Code


public class Main{

    /**//from www. j  av a  2s .co m
     * Join int array into string with sepStr
     * @param ints
     * @param seperator
     * @return
     */
    public static String join(int[] ints, String sepStr) {
        StringBuffer sb = new StringBuffer();
        for (int i : ints) {
            sb.append(i + sepStr);
        }
        if (ints.length > 0)
            sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }
    /**
     * Join long array into string with sepStr
     * @param ints
     * @param seperator
     * @return
     */
    public static String join(long[] longs, String sepStr) {
        StringBuffer sb = new StringBuffer();
        for (long i : longs) {
            sb.append(i + sepStr);
        }
        if (longs.length > 0)
            sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }
    /**
     * Join long array into string with sepStr
     * @param ints
     * @param seperator
     * @return
     */
    public static String join(String[] strs, String sepStr) {
        StringBuffer sb = new StringBuffer();
        for (String i : strs) {
            sb.append(i + sepStr);
        }
        if (strs.length > 0)
            sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

}

Related Tutorials