码迷,mamicode.com
首页 > 其他好文 > 详细

pdd面试的一道题目-Integer

时间:2019-03-06 00:54:50      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:print   span   style   pre   lse   题目   常量   面试   als   

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

标签:print   span   style   pre   lse   题目   常量   面试   als   

原文地址:https://www.cnblogs.com/CodeCafe/p/10480779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!