Java Object to String toString(Object value)

Here you can find the source of toString(Object value)

Description

Deals with primitive arrays

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static String toString(Object value) 

Method Source Code


//package com.java2s;
/*/*from   www . j a  v  a2  s.c o  m*/
 * Copyright (c) 2012 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.Arrays;

public class Main {
    /**
     * Deals with primitive arrays
     * @param value
     */
    public static String toString(Object value) {

        if (value == null)
            return null;

        if (value instanceof short[]) {
            return Arrays.toString((short[]) value);

        } else if (value instanceof int[]) {
            return Arrays.toString((int[]) value);

        } else if (value instanceof long[]) {
            return Arrays.toString((long[]) value);

        } else if (value instanceof char[]) {
            return Arrays.toString((char[]) value);

        } else if (value instanceof float[]) {
            return Arrays.toString((float[]) value);

        } else if (value instanceof double[]) {
            return Arrays.toString((double[]) value);

        } else if (value instanceof boolean[]) {
            return Arrays.toString((boolean[]) value);

        } else if (value instanceof byte[]) {
            return Arrays.toString((byte[]) value);

        } else if (value instanceof Object[]) {
            return Arrays.toString((Object[]) value);
        }

        return value.toString();
    }
}

Related

  1. toString(Object object)
  2. toString(Object object)
  3. toString(Object object)
  4. toString(Object object, Class objectClass)
  5. toString(Object val)
  6. toString(Object value)
  7. toString(Object value)
  8. toText(Object[] objs, String ch)
  9. toText(T t)