This question already has an answer here:
- What is the difference between Integer and int in Java? 11 answers
I was wondering what the difference between the variable type 'int' and the variable type 'Integer' and what the uses of using both is. Thanks!
primitive data typewhere is
wrapper class(an Object).
If you need an object then
Integer comes into picture and other
int you know it already.
Collection class accepts only object in that case you can't use simple int primitive data type.
intis a primitive. It is not an Object. An
intis a high performance, streamlined beast for calculating numbers.
Integer, is an Object that contains a single int field. An Integer is much bulkier than an int. It is sort like a box to contain the int.