Summary of the use of Java string

Source: Internet
Author: User

1 = = operator

Used to determine if the reference address of two objects is equal

2 Equals method

Used to determine whether the values (contents) of two objects are equal

3 string when referencing a variable using an anonymous object string or initializing an assignment string, a string that uses the same content as the object pool policy, and the same heap memory is shared

4 string creating a String object in new instantiation will open up different heap memory store string content, even the same content.

5 The contents of the string cannot be changed, even if a string variable is given new content, but at the same time the intelligence opens up new heap memory space to store, and does not change the contents of the original heap memory space. In a short time, the JVM is too late to reclaim the previously created garbage memory space, which can have a bad impact.

The following example is for the above content:

Stringdemo.java

Package Test.string;public class Stringdemo {public static void main (string[] args) {//TODO auto-generated method Stubboo Lean B11 = False;boolean B12 = False;boolean B21 = False;boolean B22 = False;boolean B31 = False;boolean B32 = false;boole    An b41 = False;boolean B42 = false;    if ("hello" = = "Hello") {B11 = true;    } if ("Hello". Equals ("Hello")) {B12 = true; } System.out.println (B11);//true System.out.println (B12);//true//=================================== String S    TR1 = "Hello";    String str2 = "Hello";    if (str1 = = str2) {B21 = true;    } if (Str1.equals (str2)) {B22 = true; } System.out.println (B21);//true System.out.println (B22);//true//================================== String St    R3 = "Hello";    String STR4 = new String ("Hello");    String STR5 = new String ("Hello");    if (STR3 = = STR4) {B31 = true;    } if (Str3.equals (STR4)) {B32 = true;    } if (STR5 = = STR4) {b41 = true; } if (Str5.equals (STR4)) {B42 = True } System.out.println (B31);//false System.out.println (B32);//true System.out.println (b41);//false System.out.pr    Intln (B42);//true//================================== String str = "Hello";    str = str + "World"; System.out.println (str);//hello world, Generate, memories}}

  

Summary of the use of Java string

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.