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

int和Integer的区别

时间:2018-09-19 23:33:47      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:区别   使用   整数   引用   属性   情况   方法   可见   list   

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的区别

标签:区别   使用   整数   引用   属性   情况   方法   可见   list   

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

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