I was seeing the source code of LinkedHashMap
,when the instance of LinkedHashMap
is created it first it creates header, and when a new entry is added into the LinkedHashMap
it adds the particular entry before the header, I am not able to understand these line of code
private void addBefore(Entry<K,V> existingEntry) {
after = existingEntry;
before = existingEntry.before;
before.after = this;
after.before = this;
}
what I have understood is that after pointer is pointing to the header always as i can see and before pointer is pointing to the entry before existingEntry can anybody explain me this code and how it maintain the pointer after and before.