区别:
- int是基本数据类型,Integer是引用数据类型;
- int默认值是0,Integer默认值是null;
- Integer实际是对象的引用,指向此new的Integer对象;int是直接存储数据值 ;
- int类型直接存储数值,Integer需要实例化对象,指向对象的地址。
package HelloWorld;
public class Intandinteger {
@SuppressWarnings("removal")
public static void main(String[] args) {
//-128 ~ +127 之间
Integer a = 5;
int b = 5;
@SuppressWarnings("removal")
Integer c = new Integer(5);
Integer d = 5;
System.out.println(a.equals(b)); //true
System.out.println(a == b);
System.out.println(a.e