How to convert string to int in java

Integer.parseInt(string s) method

Use the parseInt() method of the java Integer class to convert. Since non-numbers may appear in the string to be converted, the exception of NumberFormatException needs to be caught.

Example:

public class test1 {
    public static void main(String[] args) {
        String test_str = "123";
        try {
            int test_int = Integer.parseInt(test_str);
            System.out.println(test_int);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
}

Guess you like

Origin blog.csdn.net/kevinjin2011/article/details/129265511