In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the "Java basis" = "what is the difference between the equals method and the Java method". In the daily operation, I believe that many people have doubts about the difference between the Java basis "= =" and the equals method. Xiaobian consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for you to answer the "Java basis" = "what's the difference between the equals method and the basic Java method?" Next, please follow the editor to study!
If the data pointed to by a variable is of object type, then two blocks of memory are involved, the object itself occupies a piece of memory (heap memory), and the variable also takes up a piece of memory, such as Objet obj = new Object (); the variable obj is one memory, and new Object () is another memory, so the value stored in the memory corresponding to the variable obj is the first address of the memory occupied by the object. For variables that point to the object type, if you want to compare whether two variables point to the same object, that is, to see whether the values in memory corresponding to the two variables are equal, you need to use the = = operator to compare.
The equals method is used to compare whether the contents of two independent objects are the same, just as to compare whether two people look the same. The two objects it compares are independent. For example, for the following code:
String a=new String ("foo")
String b=new String ("foo")
Two new statements create two objects, and then point to one of the objects with the variables aforme b, which are two different objects whose first addresses are different, that is, the values stored in an and b are different, so the expression axiom roomb will return false, and the contents of the two objects are the same, so the expression a.equals (b) will return true.
In actual development, we often compare whether the contents of the passed string are equal, for example, String input =... ; input.equals ("quit"), many people use = = to make a comparison without paying attention, which is wrong. If you look at a few actual teaching videos of projects on the Internet, there are a lot of such mistakes. Remember, string comparisons basically use the equals method.
If a class does not define its own equals method, it inherits the equals method of Object. The implementation code of the equals method of the Object class is as follows:
This means that if a class does not define its own equals method, its default equals method (inherited from the Object class) is to use the = = operator and to compare whether the object pointed to by the two variables is the same object, then using equals and using = = will get the same result, and always return false if you compare two separate objects.
At this point, the study on the "Java basis" = "what's the difference between the equals method and the equals method" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.