Skip to main content

Posts

Showing posts with the label LinkedHashMap

LinkedHashMap vs. HashMap?

-- A LinkedHashMap differs from HashMap in that the order of elements is maintained. A HashMap has a better performance than a LinkedHashMap because a LinkedHashMap needs the expense of maintaining the linked list. The LinkedHashMap implements a normal hashtable, but with the added benefit of the keys of the hashtable being stored as a doubly-linked list.  Both of their methods are not synchronized. Let's take a look their API documentations: The HashMap is a hash table with buckets in each hash slot. Like in the API documentation: This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very...