String comparison == and the difference between equals method

String is a reference type, so if you use == to compare the memory reference address of String, not the value to be compared, and the equals method compares the value, so to judge whether a string is equal, use the equals method, and judge whether it is null If it is, null means that the value memory is empty, so use ==.
Regarding the difference between null and "", null means that the memory is empty, and "" means that the content is empty.

Value transfer:

Method call, passing it the actual parameter values to the corresponding formal parameters, is a function of the received copy of the original value, at this time there are two basic types are equal, i.e. in the form of parameters and the actual parameters in the memory , after the method of The operation is to modify the value of the formal parameter and does not affect the value of the actual parameter .

Pass by reference:

Also known as transfer address. When the method is called, the reference of the actual parameter (address, not the value of the parameter) is passed to the corresponding formal parameter
in the method , and the function receives the memory address of the original value; in the method execution, the content of the formal parameter and the actual parameter are the same , Point to the same memory address, the reference operation during method execution will affect the actual object .

Guess you like

Origin blog.csdn.net/qq_36073688/article/details/84549007