HashMap internally uses a Node <K, V> array vs Hashtable internally uses a Map.Entry <K, V> array, why is this an internal difference?

HashMap

internally uses Node<K, V>

array

vs Hashtable

internally uses Map.Entry<K, V>

array

why this is an internal difference:

HashMap uses an inner Node class with Map.Entry implementation.

static class Node<K,V> implements Map.Entry<K,V> {
    final int hash;
    final K key;
    V value;
    Node<K,V> next;

    Node(int hash, K key, V value, Node<K,V> next) {
        this.hash = hash;
        this.key = key;
        this.value = value;
        this.next = next;
    }

      

Hashtable uses Map.Entry.

private static class Entry<K,V> implements Map.Entry<K,V> {
    final int hash;
    final K key;
    V value;
    Entry<K,V> next;

    protected Entry(int hash, K key, V value, Entry<K,V> next) {
        this.hash = hash;
        this.key =  key;
        this.value = value;
        this.next = next;
    }

      

the seams are the same, but they are different.
Is there any specific reason for using HashMap

uses Node<K,V>

array

instead Map.Entry<K,V>

array

?

+3


source to share


1 answer


Both use the interface Map.Entry

. HashTable

which precedes HashMap

provides a private class implementation that is only accessible within the class HashTable

. Hence, it would be impossible to use it in HashMap

.



0


source







All Articles