Hashing used by a hashtable?

What hashing method is used in the implementation Hashtablein Java?

+3
source share
2 answers

In Java, a class Objectdefines a method int hashCode(). Each class implements this in a different way or not at all. The default implementation is a call System.identityHashCode(this).

Hashtableuses the value returned hashCode(), but trims it according to the size of the table.

By the way, the Hashtableold one. If you want to use it, you must use HashMapor ConcurrentHashMap.

+6
source

@Bart , , Hashtable. . hash(, :

119           public int getKeyHash() {
120               return key.hashCode();
121           }

, , key - Object:

 89       private static class Entry<K, V> extends MapEntry<K, V> {
 90           Entry<K, V> next;

, String, hashCode(). Object, hashCode(). ( Object) hashCode().

Object :

 33     public int hashCode() {
 34         return VMMemoryManager.getIdentityHashCode(this);
 35     }

!

+3

Source: https://habr.com/ru/post/1782442/


All Articles