Difference between int and Integer in Java

reader

Difference between int and Integer in Java

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.

Usage example

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));

why?

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

Difference between int and Integer in Java
Understand the difference between int and Integer and BigInteger in java and float and double
Difference between final and Immutable in Java
[Java] Difference between == and equals
Difference between next () and nextLine () in Java Scanner
[Java] Difference between Hashmap and HashTable
[JAVA] Difference between abstract and interface
[Java] Difference between array and ArrayList
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
Is short-circuit evaluation really fast? Difference between && and & in Java
Difference between pop () and peek () in stack
[For beginners] Difference between Java and Kotlin
Difference between getText () and getAttribute () in Selenium
Arrylist and linked list difference in java
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList
[Java] Difference between Intstream range and rangeClosed
Difference between i ++ and ++ i
Distinguish between positive and negative numbers in Java
[Java] Difference between "final variable" and "immutable object"
Difference between product and variant
[Java] Difference between equals and == in a character string that is a reference type
Difference between redirect_to and render
Rails: Difference between resources and resources
Difference between puts and print
Difference between redirect_to and render
About the difference between classes and instances in Ruby
Difference between CUI and GUI
Difference between variables and instance variables
[JAVA] What is the difference between interface and abstract? ?? ??
Difference between class and instance
Difference between bundle and bundle install
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
java Generics T and? Difference
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
What is the difference between Java EE and Jakarta EE?
Difference between render and redirect_to
[Java beginner] Difference between length and length () ~ I don't know ~
Difference between Java and JavaScript (how to find the average)
About the difference between "(double quotation)" and "single quotation" in Ruby
Jersey --What is Difference Between bind and bindAsContract in HK2?
Difference between element 0, null and empty string (check in list)
[Java] Difference between assignment of basic type variable and assignment of reference type variable
[Java] Check the difference between orElse and orElseGet with IntStream
Think about the differences between functions and methods (in Java)
Differences in how to handle strings between Java and Perl
[Java] Difference between Stack Overflow Error and Out Of Memory Error
[Ruby] Difference between get and post
Difference between render method and redirect_to
Difference between interface and abstract class
Difference between == operator and equals method
Differences between "beginner" Java and Kotlin
[Terminal] Difference between irb and pry
JavaServlet: Difference between executeQuery and executeUpdate
Encoding and Decoding example in Java
[Ruby] Difference between is_a? And instance_of?