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