如何散列在java中的作品?作品、java

2023-09-11 23:16:00 作者:我是流氓我怕谁

我试图想办法的有关散列在java中。 如果我想一些数据存储在一个HashMap例如,将它具有某种潜在的哈希表与hashvalues​​? 或者,如果有人能够给如何散列以良好的工作和简单的解释,我真的AP preciate吧。

I am trying to figure something out about hashing in java. If i want to store some data in a hashmap for example, will it have some kind of underlying hashtable with the hashvalues? Or if someone could give a good and simple explanation of how hashing work, I would really appreciate it.

推荐答案

在Java中的哈希值是通过的 公众诠释哈希code() 这是在对象类中声明,它是对所有的基本数据类型实现的。一旦你实现你的自定义数据对象的方法,那么你就不需要担心如何将这些在被Java提供的其他数据结构中使用。

Hash values in Java are provided by objects through the implementation of public int hashCode() which is declared in Object class and it is implemented for all the basic data types. Once you implement that method in your custom data object then you don't need to worry about how these are used in miscellaneous data structures provided by Java.

的说明:实施该方法需要也具有的 公共布尔等于(对象o) 以一致的方式实施。

A note: implementing that method requires also to have public boolean equals(Object o) implemented in a consistent manner.