Java.lang Package Classes

Java - String valueOf() Method



The Java string valueOf() method returns the string representation of the object argument.

Syntax

public static String valueOf(Object obj)

Parameters

obj specify an object.

Return Value

Returns "null" if the argument is null, otherwise, the value of obj.toString() is returned.

Exception

NA.

Example:

In the example below, valueOf() method returns the string representation of the object argument.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    Object x = "HELLO";
    System.out.println(String.valueOf(x));
  }
}

The output of the above code will be:

HELLO

❮ Java.lang - String