包装类
基本数据类型 | 包装类 |
---|---|
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
char | Char |
boolean | Boolan |
***Integer Integer 类在对象中包装了一个基本类型 int 的值。Integer 类型的对象包含一个 int 类型的字段。
int Integer 的区别:
- int 是基本数据类型,Integer是引用数据类型,也是int包装类。提供了对整数类型操作的方法。允许自动拆装箱。
举例
public class Test2 {
public static void main(String[] args) {
//基本数据类型
int a = 10;
//包装类型 自动填装
Integer b =10;
//b包装类型 自动装箱
int c =b;
//包装类提供了关于基本数据转换的方法和属性
//包装类的属性
// System.out.println(Integer.MAX_VALUE);
//System.out.println(Integer.MIN_VALUE);
//构造方法
Integer d = new Integer("13");
//System.out.println(d+1);
//常见方法
//System.out.println(b.compareTo(d));//比较前后两个值大小,返回一个整数
//System.out.println(d.doubleValue());
String abc = "154";
int parseInt = Integer.parseInt(abc);
System.out.println(parseInt);
//Integer 的默认值是什么null
//测试对象相等的方法
//IntegerEquals();
}
private static void IntegerEquals() {
Integer a = 128;
Integer b = 128;
System.out.println(a==b);
System.out.println(a.equals(b));
System.out.println("***********");
Integer c = new Integer(10);
Integer d = new Integer(10);
System.out.println(c==d);
}