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
mapoperations, , 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 oflinkedhashmaprequires time proportional size of map, regardless of capacity. iteration onhashmapmore 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
Post a Comment