Java Object Array to String convertObjectToString(Object obj)

Here you can find the source of convertObjectToString(Object obj)

Description

Converts the provided object to String

License

Open Source License

Declaration

public static String convertObjectToString(Object obj) 

Method Source Code

//package com.java2s;
/*/* w w  w . j av  a 2 s  .  c om*/
 * %W% %E% %U%
 *
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    /** Converts the provided object to <code>String</code> */
    public static String convertObjectToString(Object obj) {
        if (obj == null)
            return "";

        String s = "";
        if (obj instanceof byte[]) {
            byte[] bArray = (byte[]) obj;
            for (int i = 0; i < bArray.length; i++)
                s += bArray[i] + " ";
            return s;
        }

        if (obj instanceof int[]) {
            int[] iArray = (int[]) obj;
            for (int i = 0; i < iArray.length; i++)
                s += iArray[i] + " ";
            return s;
        }

        if (obj instanceof short[]) {
            short[] sArray = (short[]) obj;
            for (int i = 0; i < sArray.length; i++)
                s += sArray[i] + " ";
            return s;
        }

        return obj.toString();

    }
}

Related

  1. convertObjectArrayToStringArray(Object[] array)
  2. convertObjectArrayToStringArray(Object[] objectArray)
  3. convertObjectToString(Object obj)
  4. convertObjectToString(Object object)
  5. convertObjectToString(Object value)
  6. objectArrayToString(Object object)
  7. objectArrayToString(Object[] arr)