The string class is a special class in Java

Source: Internet
Author: User

The string class is a special class in Java, the final class in string, and the value of a string cannot be duplicated. So there is a string pool in the Java VM (virtual machine) that is dedicated to storing strings. If you encounter string a= "Hello" (note that there is no new, not creating a string), the system looks for "Hello" in the string pool, and there is no "hello" in the string pool, then the system saves the string to the string pool and then "Hello" The address in the string pool returns a. If the system encounters a string b= "Hello" again, the system can find "Hello" in the string pool. The address is returned to B, where A and B are the same.

String a= "Hello";

System.out.println (a== "Hello");

The return value of the system is true.

1  PackageTomtext;2 3  Public classtomtext_36 {4     Private intDay ;5     Private intmonth;6     Private intYear ;7      PublicTOMTEXT_36 (intDintMinty) {        8day=D;9Month=m;TenYear=y; One     } A      Public voidSetDate (intDintMinty) { -day=D; -Month=m; theYear=y; -     } -      Public voidprintdate () { -System.out.println ("Today is" +year+ "year" +month+ "month" +day+ "Day"); +     } -      +      Public Static voidMain (string[] args) { ATomtext_36 t=NewTOMTEXT_36 (3,4,2004); at t.printdate (); -T.setdate (4, 5, 2018); - t.printdate (); -          -     } -  in}

The string class is a special class in Java

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.