A brief introduction to relational operators in Java programming

In the process of Java programming, we often encounter comparing the size relationship between basic types or objects. Let's see how to compare. The source code is as follows:

Output results:

When comparing basic types, such as int and double (N3, N4), use = =,! = to compare the size between them; however, for new objects (N1, N2), you must use the equals () method to compare the size relationship between the two objects.

For user created classes (N5, N6), the equals () method must be overloaded when comparing size relationships, because the default behavior of the equals () method is to compare references rather than the contents of objects.

Most Java class libraries implement the equals () method to compare the contents of objects, not references to objects.

summary

The above article is all the content shared by Xiaobian. I hope it can give you a reference and support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>