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 :

DataType Parameter Description
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.