We will delve into the difference between ** ʻint and Integer `**.
The Integer type is a wrapper for the int type, and methods for manipulating the int type are provided.
For example, it is used when you want to cast (type conversion) from int type to String type.
int price = 100;
// int -> Integer
Integer priceRap = price;
// Integer -> String
System.out.println("price : " + priceRap.toString());
//I want to double
Double priceDouble = priceRap.doubleValue();
//Double and tax calculation?
Double per = 1.1;
System.out.println("Payment amount : " + (priceDouble * per));
The reason why int and Integer exist separately is that the computer processes primitive types such as int type.
WebAPI JSON also uses primitive types and does not send object types.
The Integer type is required when you want to process, save, or perform any operation on the data, so use it properly as needed.
Recommended Posts