Java Utililty Methods Object to String

List of utility methods to do Object to String

Description

The list of methods to do Object to String are organized into topic(s).

Method

StringobjToString(Object obj)
obj To String
return obj != null ? obj.toString() : "";
String[]objToString(Object[] obj)
obj To String
if (obj == null)
    return null;
String[] str = new String[obj.length];
for (int i = 0; i < obj.length; i++) {
    str[i] = obj[i].toString();
return str;
StringtoString(Object o)
to String
if (o instanceof Object[])
    return Arrays.deepToString((Object[]) o);
else if (o instanceof byte[])
    return Arrays.toString((byte[]) o);
else if (o instanceof short[])
    return Arrays.toString((short[]) o);
else if (o instanceof int[])
    return Arrays.toString((int[]) o);
...
StringtoString(Object obj)
Converts the object to a string.
return "";
StringtoString(Object obj)
If the obj is an array, toString() method of Arrays is called.
if (obj == null) {
    return "null";
final Class<?> clazz = obj.getClass();
if (!clazz.isArray()) {
    return obj.toString();
final Class<?> componentType = obj.getClass().getComponentType();
...
StringtoString(Object object)
Returns a String representation of the given object.
if (object == null) {
    return "null";
Class c = object.getClass();
StringBuffer sb = new StringBuffer();
if (Map.class.isAssignableFrom(c)) {
    Map map = (Map) object;
    sb.append("{ ");
...
StringtoString(Object object)
to String
return Objects.toString(object);
StringtoString(Object object)
to String
if (object instanceof Object[]) {
    return Arrays.deepToString((Object[]) object);
} else {
    return String.valueOf(object);
StringtoString(Object object)
to String
String result;
if (object.getClass().isArray()) {
    Class readingClass = object.getClass().getComponentType();
    if (Integer.TYPE.equals(readingClass)) {
        result = Arrays.toString((int[]) object);
    } else if (Long.TYPE.equals(readingClass)) {
        result = Arrays.toString((long[]) object);
    } else if (Double.TYPE.equals(readingClass)) {
...
StringtoString(Object object, Class objectClass)
to String
if (null == object) {
    return "null";
final String toString = object.toString();
if (isStringEmpty(toString)) {
    return "\"\"";
} else if (String.class.equals(objectClass)) {
    return "\"" + toString + '\"';
...