As the question, I believe this question has been raised by countless JavaProgramPersonnel are confused. In fact, as long as they are clear about the following points, they will be able to distinguish their differences and choose the appropriate method when appropriate:
The equals method (inherited by the string class from its superclass) is used to detect whether two objects are equal, that is, whether the content of the two objects is equal.
==: It has different functions for comparing and referencing basic data types:
Compares the basic data types. If the two values are the same, the result is true.
When comparing references, if the reference points to the same object in the memory, the result is true.
Eg:
S1 = new string ("Sony"); // creates a String object.
S1.equals ("Sony"); // returns true to compare whether the content of the S1 object is "Sony ".
S1 = "Sony" // return false to compare whether the address of the S1 object stored in the memory is the same as that of the Sony object.
// If
S1 = "Sony"; // note the difference between the assignment method and the above.
S1 = "Sony" // return true