Home >>Java String Methods >Java String valueOf() Method

Java String valueOf() Method

Java String valueOf() Method

The valueOf() method in java string is used to transforms various types of values into strings. With the help of string valueOf() method, you can convert int to string, long to string, boolean to string, string character, float to string, double to string, string object and string char array.

Syntax

public static String valueOf(boolean b)  
public static String valueOf(char c)  
public static String valueOf(char[] c)  
public static String valueOf(int i)  
public static String valueOf(long l)  
public static String valueOf(float f)  
public static String valueOf(double d)  
public static String valueOf(Object o)  

Returns

It is used to return string representation of given value

Java String valueOf() Method Example 1


public class MyClass
{  
public static void main(String args[])
{  
int Num=15;  
String n1=String.valueOf(Num);  
System.out.println(n1+12);
}
}  

Output:
1512

Java String valueOf() Method Example 2


public class MyClass 
{  
    public static void main(String[] args) 
	{  
        float f  = 19.05f;    
        double y = 19.02;  
        String z1 = String.valueOf(f);    
        String z2 = String.valueOf(y);  
        System.out.println(z1);  
        System.out.println(z2);  
    }  
}  

Output:
19.05
19.02