Java String valueOf(Object obj) method example

HQ » Java Tutorial » java.lang » String » toLowerCase(Locale locale) method example
Java String valueOf(Object obj) method example 2018-02-19T13:16:21+00:00

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.

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 :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.