Java - Write code to Convert array to String using StringBuilder

Requirements

Write code to Convert array to String

Use the splitor symbol to join the string

Hint

Use StringBuilder class to append the string.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String[] array = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        System.out.println(array2String(array));
    }//from www  . j a  v  a  2  s.  c om

    private final static String SPLIT_SYMBOL = "|";

    public static String array2String(String[] array) {
        if (array == null || array.length <= 0)
            return null;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < array.length - 1; i++) {
            builder.append(array[i]);
            builder.append(SPLIT_SYMBOL);
        }
        builder.append(array[array.length - 1]);
        return builder.toString();
    }
}