Java basics: notes for the string class

Source: Internet
Author: User
/** String is an unchangeable class. Once created, the character sequence contained in the object is unchangeable * the content of a string object cannot be changed, once the content variable is changed to a new String object, * string constants and basic type constants are stored in an independent constant pool of JVM * string uses private final char value []. implement storage */public class stingdemo {public static void main (string [] ARGs) {string S1 = "hello"; string S2 = "hello"; // S1, S2 points to the same region in the constant pool system. out. println (S1 = S2); // true // The equals () method compares the content system. out. println (s1.equals (S2); // truesystem. out. println ("========================"); string S3 = new string ("well "); string S4 = new string ("well"); // S3, S4 points to different addresses in the heap, but its content is located in the same region of the constant pool system. out. println (S3 = S4); // falsesystem. out. println (s3.equals (S4); // true }}

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.