常见对象(int和String类型的相互转换)

public class Test03 {
    //基本数据类型包装类有八种,其中其中都有parsexxx的方法
    //可以加将这七种字符串表现形式转换成基本数据类型
    //char的包装类Character中没有paraseXxx的方法,字符串到字符的转换通过toCharArray()可以将字符串转换成字符数组
    public static void main(String[] args) {
        int i = 100;
        //int转换 成String
        String s1 = i + "";
        
        String s2 = String.valueOf(i);
        System.out.println(s1);
        
        Integer i2 = new Integer(i);
        String s3 = i2.toString();
        
        String s4 = Integer.toString(i);
        System.out.println(s1);
        
        //String --->int
        String s = "200";
        Integer i3 = new Integer(s);
        int i4 = i3.intValue();  //将Integer转换成int数
        
        int i5 = Integer.parseInt(s); //将String转换成int
        
    }
}

猜你喜欢

转载自www.cnblogs.com/happystudyhuan/p/10734568.html