1. Conversion of data types between shaping and character type:
There are two ways to convert an int into char:
① is a Unicode encoding using char
Example: int num1 = 8;
Char ch1 = (char) (NUM1 + 48);
two. Char converted to int type
(char is the base data type, character is its wrapper type.) )
int num2 = Integer.parseint (Ch2.tostring ()); /span>
② is a Unicode encoding using char
Example: char CH3 = ' 8 ';
int num3 = ch3-48;
2. Conversion between the base data type and the string:
convert an int to string
①. converting integers to character type
String num = integer.tostring (int n);
②.long type conversion to character type
String num = long.tostring (Long n);
③.short type conversion to character type
String num = short.tostring (short n);
④.float type conversion to character type
String num = float.tostring (Float n);
⑤.double type conversion to character type
String num = Double.tostring (Double N);
two. String converted to int
①. Convert to int
Int/integer num = Integer.parseInt ( String str); /span>
②. Convert to Long
Long/long num = Long.parselong (String str); /span>
③. Convert to Short type
Short/short num = Short.parseShort ( String str);
④. Convert to float type
Float/float num = float.parsefloat (String str); /span>
⑤. Convert to type double
Double/double num = double.parsedouble (String str);
Mutual conversions between various types in Java