There are two ways to convert primitive types to strings:
- Use the toString() method of the wrapper class
- Use the valueOf() method
Eg of the String class:
int a = 10;
①String b = Integer.toString(a);
②String b1 = String.valueOf(a);
There are two ways to convert strings to primitive types:
- Call the parseXxx static method of the wrapper class
- Call the valueOf() method of the wrapper class to convert to the wrapper class of the basic type, which will be automatically unboxed
String str = "aaaa";
①int a = Integer.parseInt(str);
②int a1 = Integer.valueOf(str);