Java Utililty Methods Object to String

List of utility methods to do Object to String

Description

The list of methods to do Object to String are organized into topic(s).

Method

StringobjectToString(Object in)
object To String
return (in != null) ? in.toString() : null;
StringobjectToString(Object in, boolean ignoreNull)
Convert object to string
String strReturn = objectToString(in);
if (strReturn == null)
    return strReturn;
else if (ignoreNull) {
    if (in instanceof Double && ((Double) in).doubleValue() == 0.0)
        return null;
    else if (in instanceof Long && ((Long) in).longValue() == 0)
        return null;
...
StringobjectToString(Object o)
Emulate Object.toString on an object even if toString() was overridden.
if (o == null)
    return "null";
return o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o));
StringobjectToString(Object o)
object To String
if (o == null) {
    return "";
try {
    return o.toString();
} catch (Exception e) {
    return "Exception converting object to string FormatUtils.objectToString(): " + e.getMessage();
StringobjectToString(Object o)
object To String
return String.format("%s {instance of: %s}", o, o.getClass());
StringobjectToString(Object o, boolean quoteStrings)
object To String
if (o == null) {
    return "null";
if (o instanceof Number) {
    return o.toString();
if (quoteStrings) {
    return "'" + o.toString().replaceAll(",", "%2C") + "'";
...
StringobjectToString(Object obj)
object To String
return objectToString(obj, null);
StringobjectToString(Object obj)
Helper method to create a string representation of an object.
if (obj == null) {
    return "null";
if (obj instanceof CharSequence) {
    return "\"" + obj.toString() + "\"";
return obj.toString();
StringobjectToString(Object obj)
object To String
if (obj == null) {
    return "";
return String.valueOf(obj);
StringobjectToString(Object obj)
object To String
String result = "null";
if (obj != null) {
    String str = obj.toString();
    int len = str.length();
    if (len > MAX_CHARS) {
        len = MAX_CHARS;
    result = obj.toString().substring(0, len);
...