int和Integer之间的区别 [英] Difference between int and Integer
本文介绍了int和Integer之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int
和 Integer
之间有什么区别?是的,一个是原始
,另一个是包装
,这是正确使用它们的情况。
What is the difference between int
and Integer
. Yes, one is primitive
and another one is wrapper
, what is the situation to use them correctly.
另外有什么区别:
int i=0;
++i
and
i++
推荐答案
第1部分
一个例子..你可以使用整数
作为 HashMap
的键,但不能使用int。因为需要对象
。
One example .. you can use Integer
as the key of HashMap
but you can't use int. Because an Object
is needed.
所以你需要一个 int
作为您需要使用的对象的值整数
类。
So where you need an int
value as an object there you need to use Integer
class.
第2部分
++我是预增量
i ++是增量后
++i is pre increment i++ is post increment
例如
i = 0;
System.out.println(i++) //will print 0 then the i will be 1.
和
i = 0;
System.out.println(++i) // here i wil be incremented first then print 1.
这篇关于int和Integer之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文