The Java Foundation review for string objects, can use "=" assignment, can also use Newkeyword assignment, what is the difference between the two ways?

Source: Internet
Author: User
The string type is a commonly used type in the actual work, separated from the data type, string is a reference type and is a class defined in the API. So objects of type string can be created using new, such as String Name=new string ("string"), assigning the variable name to a value of "string", but string analogy other classes are somewhat special, can use ' = ' to directly assign values, such as String Name= "string", which is also assigned to the variable name, a value of "string", the two assignments are different, using new assignment, always creates a new object, initializes the value of the string in the new memory space, and uses "=" To assign the value, Instead of initializing a new string each time, it looks for a string from a "string instance pool" with no strings to be assigned, assuming that there is a direct reference, and if not, initializes a string and puts it into the string instance pool. In practical programming, "=" is often used to assign a value to a variable of type string.

The Java Foundation review for string objects, can use "=" assignment, can also use Newkeyword assignment, what is the difference between the two ways?

Related Article

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.