On Referring to java docs, what I know is,
When you call the PrintStream class method print (obj) / println (obj) , and inside it calls the write method with an argument like String.valueOf (obj) , shown below:
public void print(Object obj) { write(String.valueOf(obj)); }
Now String.valueOf (obj) performs the task of calling the String method, as shown below:
/** * Returns the string representation of the <code>Object</code> argument. * * @param obj an <code>Object</code>. * @return if the argument is <code>null</code>, then a string equal to * <code>"null"</code>; otherwise, the value of * <code>obj.toString()</code> is returned. * @see java.lang.Object#toString() */ public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); }
Prateek
source share