Pages

Convert primitive type to string in java

***********************************************
COMPLETE SOURCE CODE FOR : ConvertPrimitiveTypeToString.java
***********************************************


public class ConvertPrimitiveTypeToString
{
public static void main(String[]args)
{
//boolean
String a=String.valueOf(true);
System.out.println("boolean : "+a);

//byte
a=String.valueOf((byte)9);
System.out.println("byte : "+a);

//char
a=String.valueOf('a');
System.out.println("char : "+a);

//short
a=String.valueOf((short)9);
System.out.println("short : "+a);

//int
a=String.valueOf(9);
System.out.println("int : "+a);

//long
a=String.valueOf(9L);
System.out.println("long : "+a);

//float
a=String.valueOf(9.0F);
System.out.println("float : "+a);

//double
a=String.valueOf(9.0D);
System.out.println("double : "+a);
}
}


***********************************************
JUST COMPILE AND EXECUTE IT
***********************************************
Related Posts Plugin for WordPress, Blogger...