both = = and equals have the effect of equality, but what is the difference between them?
Nonsense not much to say, direct poke focus
= = compares the address, equals compares the content
Note, however, that in a Java virtual machine that contains a string pool (directly within this pool), the same contents of the string directly correspond to the same object ... Is that a little abstract, for example, to be clear?
String s1= "Hello"; String S2=new string ("Hello"); s1== "Hello";//true, because all points to the direct amount "Hello" s1==s2;//false, because S1 points to a string in the string pool, and S2 is an instance of new. The objects they point to///are different, that is, their addresses are different
Equals is relatively easy to understand, as long as the content is the same, the return ture,== content is not necessarily true, beginners can easily make mistakes here, such as the above example
This article is from the "Kinghacker" blog, make sure to keep this source http://kinghacker.blog.51cto.com/7767090/1622735
The difference between "= =" and equals in Java string (first blog)