Java Object to String objectToString(Object[] obj)

Here you can find the source of objectToString(Object[] obj)

Description

object To String

License

Open Source License

Declaration

public static String objectToString(Object[] obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String objectToString(Object[] obj) {
        if (obj == null) {
            return "";
        }//  w  w  w  . ja  v a  2 s .  c  om
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < obj.length; i++) {
            if (obj[i] == null) {
                sb.append("null,");
                continue;
            }
            try {
                sb.append((String) obj[i] + ",");
            } catch (Exception e) {
                sb.append(obj[i].toString() + ",");
            }
        }
        return sb.toString();
    }

    public static String toString(Object object, String defaultvalue) {
        if (object == null) {
            return defaultvalue;
        }
        if (object instanceof String) {
            return (String) object;
        }
        return object.toString();
    }

    public static String toString(Object[] obj) {
        if (obj == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < obj.length; i++) {
            sb.append(obj[i]);
            if (i < obj.length - 1) {
                sb.append(",");
            }
        }
        return sb.toString();
    }
}

Related

  1. objectToString(Object object)
  2. objectToString(Object object, String defaultValue)
  3. objectToString(Object objectStr)
  4. objectToString(Object x)
  5. ObjectToString(Object x)
  6. objectToStringNoNull(Object obj)
  7. objToString(Object obj)
  8. objToString(Object obj)
  9. objToString(Object obj)