What is the diference between "int" and "Integer"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the diference between "int" and "Integer"?

Are "int" and "Integer" the same class object? Can I do ArrayList<int> ? Why?

20th Oct 2016, 4:29 PM
El Flo
El Flo - avatar
5 Answers
+ 5
int is a primitive data type and Integer is class that contains only one field of type int. Every primitive data tipe has own class for example byte data type has Byte class, double data type has Double class, boolean data type has Boolean class.
20th Oct 2016, 6:02 PM
Nemanja
+ 3
No you cant have an arrayList of primitives, so if you want to use integers. You'd have the helper/wrapper class for int which is "Integer". Ex. Below: List<Integer> ArrayOfInts = new ArrayList<Integer>();
20th Oct 2016, 11:16 PM
Ousmane Diaw
+ 2
int is a primitive data type while integer is class or just any name which we used to identify int.
18th Nov 2016, 8:35 AM
Sandeep Kumar Pandey
Sandeep Kumar Pandey - avatar
+ 1
int is a primitive data type in java. While Integer is a predefined class for primitive data type int. As ArrayList is used to store group of objects, you have to specify a class name as its type. Thus, Integer is a class name and int is its datatype
19th Feb 2017, 7:47 AM
Vaishnavi Soni
Vaishnavi Soni - avatar
0
int and integer are the same thing... we use int as the short form of integer.. integer=0,1,2 3
14th Feb 2017, 11:56 AM
Sarthak Sharma
Sarthak Sharma - avatar