Convert primitive type values to string with String.valueOf method in Java
Description
The following code shows how to convert primitive type values to string with String.valueOf method.
Example
//from w w w . ja va 2s . c om
public class Main {
public static void main(String[] args) {
String s = String.valueOf(false);
System.out.println(s);
s = String.valueOf('A');
System.out.println(s);
char[] c = { 'a', 'b', 'c' };
s = String.valueOf(c);
System.out.println(s);
s = String.valueOf(c, 0, 2);
System.out.println(s);
s = String.valueOf(3.5d);
System.out.println(s);
s = String.valueOf(2.5f);
System.out.println(s);
s = String.valueOf(59);
System.out.println(s);
s = String.valueOf(8000l);
System.out.println(s);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »