The
toString() method is defined in the
java.lang.Object class and returns a string representation consisting of the object's class name followed by the "@" symbol and its hash code in hexadecimal format:
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
The
java.util.Objects class provides utility methods for safe string conversion of objects:
public static String toString(Object o) {
return String.valueOf(o);
}
public static String toString(Object o, String nullDefault) {
return (o != null) ? o.toString() : nullDefault;
}
The
java.util.Arrays class provides utility methods to get string representations of arrays,
including specific overloaded methods for each primitive type and
deepToString() for nested arrays.