int vs Integer
Default basic type int is 0; package type corresponding to the default null value Integer
Integer object will take up more memory. Integer is an object, the object needs to store metadata. But int is a primitive type of data, so take up less space
- Autoboxing: converting the basic data types to the corresponding type of packaging
Automatic unboxing: converting to the corresponding type of packaging of the basic data types
// 自动装箱
Integer integer =100;
// 自动拆箱
int i = interger;
**IntegerCache**整型对象在内部实现中通过使用相同的对象引用实现了缓存和重用,用来节省内存和提高性能
Integer i = 100;
Integer j = 100;
System.out.print(i == j); //true
Integer i = 128;
Integer j = 128;
System.out.print(i == j); //false
The difference between int and Integer: speaking of JAVA interview 504
java learning the basics (c) on automatic and automatic packing unpacking