Difference Between Integer and Int in Java

In this article, we will learn about the difference between Integer and int
in Java. Let’s get right into it.
Integer
vs int
in Java
In Java, there are some primitive types that store binary values. The actual binary value for the integer you want to represent is stored in an int
. It’s not a class, and you can’t implement any methods using int
.
On the other hand, Integer
is just like any other class in Java. We store references to Integer
objects through variables of the Integer
type. There are multiple methods that you can use through Integer
. For instance, we can use Integer.parseInt(''1")
. It’s a static method that will return an int
.
The Integer
is a java class with a single field type int
. The idea here is that we can use this class whenever we need int
to act and be treated as objects. In short, Integer is a wrapper class for int
.
Wrapper Class
Unlike primitive types, the wrapper class can inherit from the Object class. So, developers can use this class with generics and object references in collections. Remember that every primitive type has its wrapper class, just like int
has Integer
.
byte
hasByte
char
hasCharacter
float
hasFloat
boolean
hasBoolean
short
hasShort
double
hasDouble
long
hasLong
Haider specializes in technical writing. He has a solid background in computer science that allows him to create engaging, original, and compelling technical tutorials. In his free time, he enjoys adding new skills to his repertoire and watching Netflix.
LinkedInRelated Article - Java Int
- Convert Int to Char in Java
- Convert Int to Double in Java
- Convert Object to Int in Java
- List of Ints in Java
- Convert Integer to Int in Java
- Check if Int Is Null in Java
Related Article - Java Integer
- Handle Integer Overflow and Underflow in Java
- Reverse an Integer in Java
- Convert Int to Binary in Java
- The Max Value of an Integer in Java
- Minimum and Maximum Value of Integer in Java
- Convert Integer to Int in Java