首页 > 其他 > 详细

int和Integer的区别

时间:2018-09-19 23:12:07      阅读:148      评论:0      收藏:0      [点我收藏+]

1)int是Java提供的8中基本类型的一种,只能用来运算,Integer是int的包装类,可以做更过的事情,因为Integer提供了很多有用的方法

2)int作为对象的属性时默认值为0,Integer作为对象属性时默认值为null。由此可见,int无法区分未赋值和赋值为0的情况,而Integer却可以区分

3)int在参数传递时是值传递,Integer是引用传递

4)当需要想容器里(例如List)存放整数时,不能使用int,只能使用Integer,因为容器里面放的都是对象。

将int转换成Integer:public Integer(int value)

将Integer装换成int: public int intValue()

int和Integer的区别

原文:https://www.cnblogs.com/0820LL/p/9678113.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!