Java- 基本数据类型对象包装类

/*
 * 基本数据类型对象包装类
 *
 * byte Byte
 * short Short
 * int Integer
 * long Long
 * boolean Boolean
 * float Float
 * double Double
 * char Character
 *
 * 基本数据类型对象包装类的最常见作用
 * 就是用于基本数据类型和字符串类型之间做转换
 *
 * 基本数据类型转成字符串
 *
 *         基本数据类型+""
 *         基本数据类型.toString()(基本数据类型值)
 *         如:Integer.toString(34);//将34整数变成"34"
 *         
 * 字符串转成基本数据类型
 * xxx a = Xxx.parseXxx(String);
 *
 * Integer i = new Integer("123");//静态方式调用
 * int num = i.intValue();//非晶态方式调用
 *
 *
 * 十进制转成其他进制
 *         toBinaryString();
 *         toHexString();
 *         toOctalString();
 *
 * 其他进制转成十进制
 *         parseInt(String,radix)
 */

public class IntegerDemo {
    
    public static void Sop(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //整数类型的最大值
//        Sop("int max:"+Integer.MAX_VALUE);
        
        //将一个字符串转成整数
        int num = Integer.parseInt("123");//必须传入数字格式的字符串
//        long x = Long.parseLong("123");
        
        Sop("num="+(num+4));
//        Sop("x="+(x+4));
        
//        Sop(Integer.toBinaryString(-6));
//        Sop(Integer.toHexString(60));
        
        int x = Integer.parseInt("110", 10);
        Sop("x="+x);
    }

}

猜你喜欢

转载自blog.csdn.net/Lydia233/article/details/102399439