1,
= The operator is used to compare whether the values of variables are equal. A better understanding is:
Int A = 10;
Int B = 10;
Then a = B will be true.
But what is hard to understand is:
String A = new string ("foo ");
String B = new string ("foo ");
If a = B, false is returned.
Pair
Variables are actually a reference. Their values point to the memory address of the object, rather than the object itself.
. Both A and B use the new operator, which means that two "foo" characters will be generated in the memory.
String. Since they are two, they are naturally located at different memory addresses. The values of A and B are actually two different memory address values. Therefore, the result is false when the "=" operator is used. True: A and
B Refers to objects whose content is "foo" and should be "equal", but the = operator does not involve the comparison of object content.
The comparison of object content is exactly what the equals method does.
2,
Public static void main (string [] ARGs)
{
String Ss = new string ("GDD ");
String dd = new string ("GDD ");
System. Out. println (ss. Equals (dd ));
System. Out. println (Ss = dd );
}
Result:
True
False