Converting datatype in Java

Below are some examples of conversion from one data type to another in java.

double to String :
String str = Double.toString(i);

long to String :
String str = Long.toString(l);

float to String :
String str = Float.tString(f);

String to integer : str = "25";
int i = Integer.valueOf(str).intValue();
int i = Integer.parseInt(str);

String to double :
Double d = Double.valueOf(str).doubleValue();

String to long:
long l = Long.valueOf(str).longValue();
Long L = Long.parseLong(str);

String to float :
Float f = Float.valueOf(str).floatValue();

decimal to binary : int i = 42;
String bin = Integer.toBinaryString(i);



  • Nice ones, must say...A good work. Hope to see some great work from your side with SQL and JAVA.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion