How is HashMap
internally implemented? I read somewhere that it uses LinkedList
while other places it mentions Arrays.
I tried studying the
HashMap internally uses Entry for storing key-value pair. Entry is of LinkedList type.
Entry contains following ->
K key,
V value and
Entry next > i.e. next entry on that location of bucket.
static class Entry {
K key;
V value;
Entry next;
public Entry(K key, V value, Entry next){
this.key = key;
this.value = value;
this.next = next;
}
}
HashMap diagram -
From : http://www.javamadesoeasy.com/2015/02/hashmap-custom-implementation.html