Conversion between JAVA primitive types and strings

There are two ways to convert primitive types to strings:

  1. Use the toString() method of the wrapper class
  2. 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:

  1. Call the parseXxx static method of the wrapper class
  2. 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);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325428423&siteId=291194637