Java Object to String objectToString(Object obj)

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

Description

Helper method to create a string representation of an object.

License

Apache License

Parameter

Parameter Description
obj the object to print

Return

a string representation of the object

Declaration

private static String objectToString(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  w  w  w.  j  ava 2s  . com
     * Helper method to create a string representation of an object.
     * 
     * @param obj the object to print
     * @return a string representation of the object
     */
    private static String objectToString(Object obj) {

        // handle 'null'
        if (obj == null) {
            return "null";
        }

        // enclose Strings in quotes
        if (obj instanceof CharSequence) {
            return "\"" + obj.toString() + "\"";
        }

        // use toString() for all other objects
        return obj.toString();
    }
}

Related

  1. objectToString(Object o)
  2. objectToString(Object o, boolean quoteStrings)
  3. objectToString(Object obj)
  4. objectToString(Object obj)
  5. objectToString(Object obj)
  6. objectToString(Object obj, String defaultvalue)
  7. objectToString(Object object)
  8. objectToString(Object object, String defaultValue)
  9. objectToString(Object objectStr)