= Is used to compare whether the values are equal. Equals is used to compare equal references. This means that not two objects are compared, but two objects are referenced, and the references of two objects are referenced by the same object.
1. Value Type
Equal value, equal
II. For reference types
1. = compare whether the values of the two variables are equal, or whether the two references point to the same memory address
2. equals checks whether the content of the two objects points to the same memory space;
For the reference type, = is similar to comparing whether the folder path is the same, while the equals method compares whether the content in the folder is the same
= Determines the value type. If the value is equal, the value is true. The same applies to equals.
Instead of allocating memory to s2, the system points "test" to s2, which is called memory optimization.
S3 and s4 are value types
O3 and o4 are reference types. If the address stored in the memory is different, = false
The content stored in the memory space is the same, so equals is true.
Is a different object, and the content is different, so it is false.
References the same object.
By: dxh_0829