pdd面试的一道题目-Integer

Posted 贾斯彼迭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pdd面试的一道题目-Integer相关的知识,希望对你有一定的参考价值。

Integer主要考的就是IntegerCache,常量池里缓存了-128~127的值。

1.

Integer a0 = new Integer(100);

Integer a1 = new Integer(100);

Integer a2 = 100;

Integer a3 = 100;

int a4 = 100;

System.out.println(a0 == a1); //false
System.out.println(a0 == a2); //false
System.out.println(a0 == a4); //true
System.out.println(a2 == a3); //true
System.out.println(a3 == a4); //true

2. 

Integer a0 = new Integer(130);

Integer a1 = new Integer(130);

Integer a2 = 130;

Integer a3 = 130;

int a4 = 130;

System.out.println(a0 == a1); //false
System.out.println(a0 == a2); //false
System.out.println(a0 == a4); //true
System.out.println(a2 == a3); //false
System.out.println(a3 == a4); //true

 

以上是关于pdd面试的一道题目-Integer的主要内容,如果未能解决你的问题,请参考以下文章