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));
    //w  w  w. ja  v a  2 s .co  m
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable