App Little public who self-study content-->integer (different from int)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.