java - Deletion in LinkedHashMap vs HashMap -


is correct deletion in linkedhashmap takes linear time. since need delete key linked list maintains order of insertion , take o(n) time. in regular hashmap deletion takes constant time.

according javadocs, not:

this class provides of optional map operations, , permits null elements. hashmap, provides constant-time performance basic operations (add, contains , remove), assuming hash function disperses elements among buckets. performance below of hashmap, due added expense of maintaining linked list, 1 exception: iteration on collection-views of linkedhashmap requires time proportional size of map, regardless of capacity. iteration on hashmap more expensive, requiring time proportional capacity.

linkedhashmap not override hashmap#remove(object key) method. latter removes entry corresponding key table , calls recordremoval() method on deleted entry, adjusts links of previous , next removed one. there no iteration on list in order delete node @ index.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -