Monday, 9 September 2013

How does put() method of LinkedHashMap internally works?

How does put() method of LinkedHashMap internally works?

I am trying to understand a internal working of linkedhashmap.
So when we call put(map,key) of linkedhashmap. Internally it calls
[createEntry][1] .
void createEntry(int hash, K key, V value, int bucketIndex) {
440 HashMap.Entry<K,V> old = table[bucketIndex];
441 Entry<K,V> e = new Entry<K,V>(hash, key, value, old);
442 table[bucketIndex] = e;
443 e.addBefore(header);
444 size++;
445 }
Here I am not able to understand the use of old variable.
Why new entry is added before the header. It should be added to the end of
linkedhashmap.
Can somebody explain this code.

No comments:

Post a Comment