LinkedHashedMap has some useful properties. It combines the best of both LinkedList and Hashmap.
From the HashMap camp, it brings the following advantages:
1) Faster access times O(1)
2) Faster add and removal times O(1)
From the LinkedList camp, it brings the following advantages:
1) Maintain insertion order
2) Iterate through the elements in insertion order
But LinkedHashMap is not perfect and it has some flaws which are not very obvious.
1) You don’t have direct control over the order of elements
2) Accessing value by index is O(n)
No direct control over order of elements
I have discussed about this problem in the following blog post.
Poor performance when accessing value by index
Sadly LinkedHashMap doesn’t expose the LinkedList. The only to access the elements is through entrySet or keySet. Set interface doesn’t support accessing elements by index either. So, the users have to resort to creating an Array from the Set. This incurs a performance hit.
Instead you can just iterate through the set to the required position. This will have same performance stats as LinkedList (O(n)) but not HashMap (O(1)).