I saw there are a lot of questions about the differences between these three. Tell me if I am wrong, but if I sum up what I could read:
Hashmap
: will be more efficient in general; O(1) (normal case), O(N) (worst case, only with bad hash algorithm)LinkedHashmap
: maintains insertion order of elements, take more memory than hashmapTreemap
: maintains elements sorted, O(log(n)) (when balanced)
My question is : Why do we need to maintain insertion order or elements sorted, if at the end the performance to insert, lookup.. are better with hashmap
?