The method of converting int to string in java

1. String.valueOf(int i) method

Use the valueOf() method of the java String class to convert.

Example:

public class test1 {
    public static void main(String[] args) {
        int test_int = 123456;
        String test_str = String.valueOf(test_int);
        System.out.println(test_str);
    }
}

2. Integer.toString(int i) method

Use the toString() method of the java Integer class to convert.

public class test1 {
    public static void main(String[] args) {
        int test_int = 123456;
        String test_str = Integer.toString(test_int);
        System.out.println(test_str);
    }
}

3. The method of adding an empty string

public class test1 {
    public static void main(String[] args) {
        int test_int = 123456;
        String test_str = test_int + "";
        System.out.println(test_str);
    }
}

Guess you like

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