Integer to String:
int i = 42;
String str = integer.tostring (i);
Or
String str = "" + I
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 ();
Or
int i = Integer.parseint (str);
String to Double:
Double d = double.valueof (str). Doublevalue ();
String to Long:
Long L = long.valueof (str). Longvalue ();
Or
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);
Decimal to hexadecimal:
int i = 42;
String hexstr = integer.tostring (i, 16);
Or
String hexstr = integer.tohexstring (i);
or (with leading zeroes and uppercase)
public class Hex {
public static void Main (String args[]) {
int i = 42;
System.out.print
(Integer.tohexstring (0x10000 | i). SUBSTRING (1). toUpperCase ());
}
}
Hexadecimal (String) to Integer:
int i = integer.valueof ("B8da3"). Intvalue ();
Or
ASCII code to String
int i = 64;
String Achar = new Character ((Char) i). ToString ();
Integer to ASCII code (byte)
char c = ' A ';
int i = (int) c; i = = DECIMAL
To extract Ascii codes from a String
String test = "ABCD";
for (int i = 0; i < test.length (); ++i) {
char C = Test.charat (i);
int j = (int) c;
System.out.println (j);
}
Integer to Boolean
b = (i!= 0);
Boolean to Integer
i = (b)? 1:0;