How a linked hashmap maintains insertion order

I know how a hashmap works internally. Linkedhashmap extends the Hashmap class. So how can Linkedhashmap support insertion order. I read the javadoc for Linkedhashmap, but there are no details about it in it. Can someone help me figure this out?

Thanks in advance.

+6
source share
4 answers

http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html .

The idea of ​​implementation is quite simple. It extends the regular hashMap (so it has all the goodies of hashMap), but also creates a double linked list when adding items.

( HashMap.Entry, ). , HEAD → Entry1 <-> Entry2... <- TAIL

HashSet ( , ).

.

+5
0

(Map.Entry) , .

.

0

The before and after link fields support a doubly linked list for all LinkedHashMap entries . Using the "before" and "after" fields, we can view all the entries in LinkedHashMap.
LinkedHashMap Inside: http://techmastertutorial.in/java-collection-internal-linked-hashmap.html

0
source

All Articles