In program development, we often need to convert between the basic data type and the string.
There are three ways to convert the base type to a string:
1. Use the ToString () method of the wrapper class
2. Using the ValueOf () method of the String class
3. Using an empty string with the base type, you get the string that corresponds to the base type data
int C = Ten=integer.tostring (c); // Method One String str2 = string.valueof (c); // Method Two String STR3 = c + ""; // Method Three
Again, there are two ways to convert a string to a basic type:
1. Call the Parsexxx static method of the wrapper class
2. The ValueOf () method that calls the wrapper class is converted to the basic type of wrapper class, and the box is automatically disassembled
String str = "8"; int d =integer.parseint (str); // Method One int e =integer.valueof (str); // Method Two
PS: Other basic types and string conversions are no longer listed here, and the methods are similar
Conversion between Java base type and string