基本数据类型的包装类
基本数据类型 包装类
* byte Byte
* short Short
* int Integer
* long Long
* float Float
* double Double
* boolean Boolean
* char Character
思考:为什么要把基本数据类型封装成一个类
在类中可以声明方法,可以使用对象调用方法
Integer
private static void Demo() {
Integer integer1 = new Integer(10);
System.out.println(integer1);
Integer integer2 = new Integer("100");
System.out.println(integer2);
int a = 60;
System.out.println("二进制:" + Integer.toBinaryString(a));
System.out.println("八进制:" + Integer.toOctalString(a));
System.out.println("十六进制:" + Integer.toHexString(a));
Integer num1 = Integer.valueOf(10);
int num2 = num1.intValue();
Integer num3 = Integer.valueOf("1000");
String string3 = num3.toString();
Integer.parseInt("100");
}
注意:
Integer num1 = 100;
Integer num2 = 100;
System.out.println(num1 == num2);
System.out.println(num1.equals(num2));
Integer num3 = 150;
Integer num4 = 150;
System.out.println(num3 == num4);
System.out.println(num3.equals(num4));
Integer num5 = new Integer(100);
Integer num6 = new Integer(100);
System.out.println(num5 == num6);
System.out.println(num5.equals(num6));
JDK1.5 自动装箱和自动拆箱
private static void fun2() {
Integer num1 = 10;
int rel = num1 + 5;
System.out.println(num1 + rel);
}
http://blog.csdn.net/huzongnan/article/list