The Equals () method, which is defined in the object class, so that every class in Java has that method, and for the Equals () method of the object class, it is the same as the reference that invokes the Equals () method. That is, whether these two references point to the same object.
public boolean equals (Object obj) {return (this = = obj);}
3. The Equals () method of String overrides the Equals () method of Object
4. For the Equals () method of the String class, it is to determine whether the current string is consistent with the contents of the passed in string.
Public boolean equals (object anobject) { if (this == anObject) { return true; } if (anobject instanceof string) { string anotherstring = (String) anobject; int n = count; if (N==anotherstring.count) { char v1[] = value; char v2[] = anotherString.value; int i = offset; int j = anotherString.offset; &nbSp; while (n--! =0) { if (v1[i++]!=v2[j++]) { return false; } return true; } } return false; }}
5. For the Equality judgment of a string object, use the Equals () method instead of = =.
6.String is a constant, and its object cannot be changed once it has been created. When you use the + sign to stitch a string, a new string object is automatically generated instead of appending content to the original string object.
7.String Pool (string pooling):
8.String s = "AAA";
1) Look for the "AAA" object in the string pool, if it does not exist, create an "AAA" object in the string pool, and then return the address of the "AAA" object in the string pool to the reference variable s, This causes S to point to the "AAA" string object in the string pool.
2) If present, do not create any objects, directly return the "AAA" object address in the string pool and assign the S reference.
9.String s = new String ("AAA");
1) First find the object "AAA" in the string pool. If so, it does not create an "AAA" object in the string pool, creates an "AAA" string object directly in the heap (heap), and then returns the address of the "AAA" object in the heap to the S reference, causing S to point to the "AAA" string object created in the heap.
2) if not, first create an "AAA" object in the string pool, then create an "AAA" object in the heap, and then return the address of the "AAA" object in the heap to the S reference, causing S to point to the "AAA" object created in the heap.
This article is from the "Java" blog, so be sure to keep this source http://5737386.blog.51cto.com/5727386/1662193
String class source code Analysis