Java --String ,int, Integer類型轉換

轉換關係如圖

stin

演示代碼

public class IntegerTets03 {
    public static void main(String[] args) {
        // String --> int

        String s1 = "100";
        int i1 =Integer.parseInt(s1);
        System.out.println(i1+1);//101

        //int -->String

        String s2 =i1+"";
        System.out.println(s2+1);//"1001"字符串

        // int --> Integer
        //自動裝箱
        Integer x =1000;
        //自動拆箱
        int y =x;

        // String --> Integer

        Integer k = Integer.valueOf("123");

        // Integer ---> String

        String k1 = String.valueOf(k);



    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章