Java Data Type Tutorial - Java String.valueOf(Object obj)








Syntax

String.valueOf(Object obj) has the following syntax.

public static String valueOf(Object obj)

Example

In the following code shows how to use String.valueOf(Object obj) method.

public class Main {
  public static void main(String args[]) {
    Object objectRef = "hello"; // assign string to an Object reference
    System.out.printf("Object = %s\n", String.valueOf(objectRef));
    
  }
}

The code above generates the following result.