Difference between 'int' and 'Integer' types


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!

int is primitive data type where is Integer is a wrapper class (an Object).

If you need an object then Integer comes into picture and other int you know it already.

All the Collection class accepts only object in that case you can't use simple int primitive data type.

An int is a primitive. It is not an Object. An int is a high performance, streamlined beast for calculating numbers.

An 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.

For more info look at Primitive Data Types and Primitive wrapper class