There are two main types of data in Java:
1. Basic data type: long,int,byte,float,double, these are just basic data types, not objects
2. Object type: Long,integer,byte,float,double and all other Java objects
For Interger and Int,integer is an object of int encapsulation, the simplest version of the package can be similar to the following encapsulation
Class Integer {
private int i;
public int intvalue () {
return i;
}
}
Because int is a data type and integer is an object, at initialization time, the int type initializes with a value of 0, and the integer initialization type is null
Object types are useful in some situations, such as Map,set containers, where item needs to be object, so it is impossible to add the basic data type directly, this time, you can only add integer and not add int
So when choosing between these two types, if we just need to define a number of type int to perform some subtraction operations or pass as parameters, then you can use int directly
But if you need to do something like an object, use an integer.
The difference between basic data types and wrapper classes in Java