There are two ways to determine whether a string is equal in Java:
1. Use the "= =" operator, which indicates whether the reference to the string is the same,
For example:
String a= "ABC";
String b= "abc";
then A==b will return true.
This is because the value of the string in Java is immutable,
The same string will only save one copy in memory, so a and B point to the same object;
Another example:
String A=new string ("abc");
string B=new string ("abc");
then A==b will return false, because A and B point to different objects.
2, using the Equals method, the method compares the contents of the string is the same,
For example: String A=new string ("abc");
string B=new string ("abc");
A.equals (b);
will return true.
so in general, to avoid these problems, judge whether strings are equal using the Equals method.
Two strings in Java are judged equal (reproduced)