+ 2

[✅SOLVED✅] Difference between int and Integer.

I am currently learning Java, and have come across a really weird thing I really can't wrap my head around. What is "int" and what is "Integer," and what is the difference?

11th Oct 2017, 2:59 AM
LunarCoffee
LunarCoffee - avatar
5 odpowiedzi
+ 23
int-primitive type. Integer-class.
11th Oct 2017, 3:02 AM
Nithiwat
Nithiwat - avatar
+ 7
Yes ArrayLists store objects only but not primitive types in Java. Good read: https://stackoverflow.com/q/5414920
11th Oct 2017, 3:24 AM
Zephyr Koo
Zephyr Koo - avatar
+ 3
OK. Thanks! So in general I should use int, and when defining new things like ArrayLists I should use Integer?
11th Oct 2017, 3:03 AM
LunarCoffee
LunarCoffee - avatar
+ 2
int drops the value after the (.), and it is a primitive type. Example, int(4.6) is 4 Integer rounds up. It is a class. Example, Integer(4.3) is equal to 5
11th Oct 2017, 4:59 AM
Saidmamad Gulomshoev
Saidmamad Gulomshoev - avatar