Here you can find the source of toString(Object object)
@SuppressWarnings("unchecked") public static String toString(Object object)
//package com.java2s; /* NOTICE//from w w w . j a va2 s . c o m * * Copyright 2006 - 2008 Grant Gardner * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed * to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF * ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the * License. * NOTICE */ import java.util.Arrays; public class Main { @SuppressWarnings("unchecked") /** * Crude way to handle nice array printing. */ public static String toString(Object object) { 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)) { result = Arrays.toString((double[]) object); } else if (Float.TYPE.equals(readingClass)) { result = Arrays.toString((float[]) object); } else if (Character.TYPE.equals(readingClass)) { result = Arrays.toString((char[]) object); } else if (Boolean.TYPE.equals(readingClass)) { result = Arrays.toString((boolean[]) object); } else if (Short.TYPE.equals(readingClass)) { result = Arrays.toString((short[]) object); } else { result = Arrays.toString((Object[]) object); } } else { result = object.toString(); } return result; } }