Java String Object Pool

Source: Internet
Author: User

The Java string is a class where the Java virtual machine instantiates 9 object pools at startup, 9 of which are used to store 8 basic data types (Int,float,double,byte,boolean,short,long, Char) wrapper class and string object.

Java String creates objects in two ways, one of which is by creating directly: String str1= "Stringhello" and the other through constructors: string Str2=new string ("Stringhello"); The former is an object that is directly generated by taking objects in the object pool.  String str3= "111"; String str4= "111"; System.out.println (STR3==STR4);==>> output is: true. This is because both STR3 and STR4 are obtained through the object pool, however, by string Str5=new string ("111"); System.out.println (STR3==STR5);==>> output is: false. This is because STR3 is obtained through the object pool, and STR5 is created directly, so the nature is different;

= =: This comparison method refers to the same nature is true, and the equal () method requires only the same value.

Java String Object Pool

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.