+ 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?
5 Answers
+ 23
int-primitive type.
Integer-class.
+ 20
+ 7
Yes ArrayLists store objects only but not primitive types in Java.
Good read:
https://stackoverflow.com/q/5414920
+ 3
OK. Thanks! So in general I should use int, and when defining new things like ArrayLists I should use Integer?
+ 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