Comparing Object Values ​​Using Hash Codes

zhaozj2021-02-12  167

Comparing Object Values ​​Using Hash Codesthe Hash Code of An Object Is An Integer Value That Company Computed Using The Value of The Object. For Example, for A

String Object, The Characters of The String Are Used to Compute The Hash Code. For an

Integer Object, The Integer Value IS Used to Compute The Hash Code.

Hash codes are typically used as an efficient way of comparing the values ​​of two objects. For example, if the hash code of the string "hello" is 33, another String object with the same contents would also a hash code of 33.

If the hash codes of two object values ​​are different, the object values ​​are guaranteed to be different. However, if the hash codes of two object values ​​are the same, the object values ​​are not guaranteed to be the same. An additional call to Object . Equals () Must Be Made to confirm That The Object Values ​​Are The Same. A Good Hash Code Algorithm Will Minimize The Chance of Two Different Values ​​Having The Same Hash Code.

The `== 'operator is the most efficient way to determine if two objects (rather than object values) are the same. However, in very limited applications, it may be necessary to get the hash code of an object (called the identity hash ..........................

转载请注明原文地址:https://www.9cbs.com/read-6799.html

New Post(0)