Java - Convert array To String

Description

Convert array To String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String[] ss = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        String delimiter = "book2s.com";
        System.out.println(arrayToString(ss, delimiter));
    }/*from  w ww  .ja  v  a  2 s . c  o m*/

    /**
     * 
     * @param ss
     * @param delimiter
     * @return
     */
    public static String arrayToString(String[] ss, String delimiter) {
        StringBuffer sb = new StringBuffer();

        if (ss != null && ss.length > 0) {
            for (int i = 0; i < ss.length; i++) {
                sb.append(ss[i]);
                if ((i + 1) < ss.length)
                    sb.append(delimiter);
            }
        }

        return sb.toString();
    }

    /**
     * 
     * @param ss
     * @param delimiter
     * @return
     */
    public static String arrayToString(String[] ss, char delimiter) {
        return arrayToString(ss, Character.toString(delimiter));
    }
}

Related Exercise