Java - Write code to convert array To String

Requirements

Write code to convert array To String

Demo

//package com.book2s;

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

    public static String arrayToString(String[] arr) {

        if (arr != null) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < arr.length; i++) {
                sb.append(arr[i]);
            }
            //***
            return sb.toString();
        } else
            return null;

    }
}

Related Exercise