Program
public class StringValueOf { public static void main(String[] args) { boolean b1 = true; byte b2 = 11; short sh = 12; int i = 13; long l = 14L; float f = 15.5f; double d = 16.5d; char chr[] = { 'j', 'a', 'v', 'a' }; StringValueOf obj = new StringValueOf(); String s1 = String.valueOf(b1); String s2 = String.valueOf(b2); String s3 = String.valueOf(sh); String s4 = String.valueOf(i); String s5 = String.valueOf(l); String s6 = String.valueOf(f); String s7 = String.valueOf(d); String s8 = String.valueOf(chr); String s9 = String.valueOf(obj); System.out.println(s1); System.out.println(s2); System.out.println(s3); System.out.println(s4); System.out.println(s5); System.out.println(s6); System.out.println(s7); System.out.println(s8); System.out.println(s9); } }
Output
true 11 12 13 14 15.5 16.5 java StringValueOf@15db9742
Description
public static String valueOf​(Object obj)
Returns the string representation of the Object argument.
Parameters:
obj – an Object.
Returns:
if the argument is null, then a string equal to “null”; otherwise, the value of obj.toString() is returned.