About string Ok1=new string ("OK"), whether to create two objects

Source: Internet
Author: User
(1) String Ok1=new string ("OK"), (2) string ok2= "OK"; the memory of the two strings is drawn: string Ok1=new string ("OK"). First, a chunk of memory is requested in the heap memory string Ok,ok1 points to its memory block object. It also checks whether the string constant pool contains an OK string, and if not, adds OK to the string constant pool. Therefore, a new String () may create two objects. String ok2= "OK". Check that the string constant pool contains an OK string, and if there is a direct point, no then add an OK string to the string constant pool and point to it. so this method creates at most one object, and it is possible not to create an object so string ok1=new string ("OK");//Create two objects String ok2= "OK";//No object created

About string Ok1=new string ("OK"), whether to create two objects

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.