Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert int into string in java
How to convert int into string in java
When converting a String type to an int type in Java, you need to use the parseInt () method or the valueOf () method in the Integer class.

Example 1:

string str = " 123 ";

Try {

int a = integer . parse int(str);

} catch(NumberFormatException e){

e . printstacktrace();

}

Example 2:

string str = " 123 ";

Try {

int b = Integer.valueOf(str)。 intValue()

} catch(NumberFormatException e){

e . printstacktrace();

}

In the process of conversion, we need to pay attention to the fact that there may be non-numeric cases in the string, so we need to catch and handle exceptions during conversion.