String Integer int 三者互转

参考动力节点视频

https://www.bilibili.com/video/BV1Rx411876f?p=618&spm_id_from=pageDriver

image

/**
 * String int Integer 三者互转
 */
public class Main {
    public static void main(String[] args) {
        //String --> int
        String s1 = "100";
        int i1 = Integer.parseInt(s1);
        System.out.println(i1);
        
        //int --> String
        int i2 = 100;
        String s2 = String.valueOf(i2);
        System.out.println("方式1:" + i2);
        String s21 = i2 + "";
        System.out.println("方式2:" + s21);

        //int --> Integer
        //自动装箱
        Integer x = 1000;

        //Integer --> int
        //自动拆箱
        int y = x;

        //String -->Integer
        Integer integer = Integer.valueOf("123");

        //Integer --> String
        String string = String.valueOf(integer);

    }
}
posted @ 2021-10-11 08:30  iiiiiiiivan  阅读(33)  评论(0)    收藏  举报