Internship Fast half a month, the recent harvest is quite big, although I am not very strong developers, not to mention what I do now or development does not have much to do with the position, software testing, oh, a little funny bar, the previous things do not mention, now has been so, then learned a night, Or to tidy up today's app small public who's study notes, for the explanation of the integer.
Before we talk about int, we all know that the data type of Java is divided into basic data types and complex data types, and int is the basic data type, which can be stored directly, instead, integer is a complex data type, and it is an object. Therefore, when the class is initialized, the variable initial value of type int is the 0,integer variable with the initial value null.
Integer is a class, is an int extension, defines a lot of conversion methods, integer is the encapsulated class of int, both can represent a numeric value, but cannot interoperate, because they are different data types, in ArrayList and HashMap, For example, int and double are not put in, because the container is loaded with object objects, which requires that the outer class of these built-in classes as object stored values into the container.
To illustrate:
ArrayList al = new ArrayList ();
int n = 40;
Integer NI = new integer (n);
Al.add (n);//Not available, data mismatch, syntax error
Al.add (NI);//Yes, array successfully added object
In addition, integers can support generics, and int does not, for example:
list<integer> list = new arraylist<integer> ();//Can
list<int> list = new arraylist<int> ();//Not Available
Summary: The number of int type can only be used for numeric operation or as a parameter to be directly declared as the basic data type of int, on the other hand, if you want to process like an object, you need to declare an integer object, Because this kind of declaration can provide a lot of objects between the conversion mode and some common methods. Therefore, as an object-oriented language, Java is best declared as an object format when declaring a variable, which facilitates the understanding of object-oriented thinking.
App Little public who self-study content-->integer (different from int)