JAVA-Integer_int和string的相互转换

package com.itheima;

public class intger_02 {
    public static void main(String[] args) {

        //int和string的相互转换
        int number=100;
        //方式一
        String s1=number+"";
        System.out.println(s1);
        //方式二
        String s2=String.valueOf(number);
        System.out.println(s2);
        System.out.println("-------------");

        //string....转换..int类型
        String s="100";
        //方式1 String-----Integer
        Integer i = Integer.valueOf(s);
        int x = i.intValue();
        System.out.println(x);
        //方式2
        int y = Integer.parseInt(s);
        System.out.println(y);



    }
}

执行结果


100
100
-------------
100

Process finished with exit code 0
posted @ 2022-11-01 21:43  NiceTwocu  阅读(36)  评论(0编辑  收藏  举报