Convert array of object To String - Android java.lang

Android examples for java.lang:String Join

Description

Convert array of object To String

Demo Code

import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

public class Main{

    public static String arrayToString(String[] array) {
        if (array == null || array.length == 0) {
            return "";
        }//from w w  w.  j a  v a  2  s. co m

        StringBuilder builder = new StringBuilder();
        for (String s : array) {
            builder.append(s).append("; ");
        }
        builder.delete(builder.length() - 2, builder.length());

        return builder.toString();
    }
    public static String arrayToString(Object[] array) {
        if (array == null || array.length == 0)
            return "[]";

        StringBuffer strings = new StringBuffer();
        strings.append("[");
        for (Object x : array) {
            strings.append(x.toString()).append("; ");
        }
        strings.delete(strings.length() - 2, strings.length());
        strings.append("]");
        return strings.toString();
    }

}

Related Tutorials