java.lang.String valueOf(Object obj)

Description :

This java tutorial shows how to use the valueOf(Object obj) method of String class of java.lang package. This method returns a string representation of the Object obj specified as method argument. To make it simple it is only simple call to the Object.toString() method.

Method Syntax :

public static String valueOf(Object obj)

Parameter Input :

Object|obj|The object parameter we are interested to get the String equivalent

Method Returns :

The method valueOf(Object obj) returns a String object which the equivalent of the toString() of Object. If the Object is null, the return value will be null.

Compatibility Version :

Since the beginning

Exception :


Discussion :

The java method, String valueOf(Object obj) should be accessed statically thus we should do the following String.valueOf(Object obj). The toString() method is the String representation of Object class. The toString() method is advised to be overridden to give a more sensible value of our Object.

Java Code Example :

This java example source code demonstrates the use of valueOf(Object obj) method of String class. We have used the Employee class to demonstrate how to override the toString() method of Object class which our Employee class inherited automatically.

Sample Output :

Running the valueOf() method example source code of java String class will give you the following output

java string indexOf method example

java string indexOf method example

Exception Scenario :

Not Applicable

Suggested Reading List :

References :