People who are familiar with C + + must know the code for two string comparisons:
(STRING1==STRING2)
But in Java, this code returns false even if the two strings are exactly the same
String1.equals (string2) must be used in Java to judge
Add
If:
String S1=new string ("Hello");
String S2=new string ("Hello");
Then (S1==S2) =false
If:
String s1= "Hello";
String s2= "Hello";
Then (S1==S2) =true;
Because they point to the same object.
If the values of other variables are assigned to S1 and S2, false is returned, even if the content is the same, because it is not pointing to the same object. So it is recommended to use Equals (), because equals is the real content.
For example:
String1= "AAA";
String2= "AAA";
The two strings should of course be equal.
If string1==string2 with an expression, the value of the expression is false
If the expression is String1.equals (string2), the value of the expression is true
So you should use String1.equals (string2), which in the IF statement is
if (String1.equals (string2) ==true)//String equal, ...
String1==string2, is equal value, and the memory address is equal, is completely equal
String1.equals (string2) is true, only values are equal