Here you can find the source of objectToString(Object x)
private static String objectToString(Object x)
//package com.java2s; public class Main { private static String objectToString(Object x) { // Extreme compatibility with StringBuilder.append(null) String s;// ww w .j a va 2s . c o m return (x == null || (s = x.toString()) == null) ? "null" : s; } /** * Like Arrays.toString(), but caller guarantees that size > 0, * each element with index 0 <= i < size is a non-null String, * and charLength is the sum of the lengths of the input Strings. */ static String toString(Object[] a, int size, int charLength) { // assert a != null; // assert size > 0; // Copy each string into a perfectly sized char[] // Length of [ , , , ] == 2 * size final char[] chars = new char[charLength + 2 * size]; chars[0] = '['; int j = 1; for (int i = 0; i < size; i++) { if (i > 0) { chars[j++] = ','; chars[j++] = ' '; } String s = (String) a[i]; int len = s.length(); s.getChars(0, len, chars, j); j += len; } chars[j] = ']'; // assert j == chars.length - 1; return new String(chars); } }