+ 2
What is the diference between "int" and "Integer"?
Are "int" and "Integer" the same class object? Can I do ArrayList<int> ? Why?
5 Respostas
+ 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.
+ 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>();
+ 2
int is a primitive data type while integer is class or just any name which we used to identify int.
+ 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
0
int and integer are the same thing... we use int as the short form of integer.. integer=0,1,2 3