tag:blogger.com,1999:blog-694855878384792308.post7856210595005654826..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Difference between HashMap and LinkedHashMap in Javajavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-694855878384792308.post-13667260594072343022018-07-07T02:23:06.701-07:002018-07-07T02:23:06.701-07:00i think point 3 is not correct.please review that ...i think point 3 is not correct.please review that point<br />Anonymoushttps://www.blogger.com/profile/17387574100157918113noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-35252143945043927972017-08-07T18:54:55.344-07:002017-08-07T18:54:55.344-07:00very nice explainationvery nice explainationAkash Kumar Dashttps://www.blogger.com/profile/14625211043322925343noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-38235879330552045452013-04-07T22:17:57.490-07:002013-04-07T22:17:57.490-07:00Few things to note, while using LinkedHashMap in J...Few things to note, while using LinkedHashMap in Java :<br /><br />1) Default ordering provided by LinkedHashMap is the order on which key is inserted, known as insertion order, but LinkedHashMap can be created with another ordering called access ordrder, which is defined by accessing entries.<br /><br />2) Re-entering a mapping, doesn't alter insertion order of LinkedHashMap. For example, if you already have mapping for a key, and want to update it's value by calling put(key, newValue), insertion order of LinkedHashMap will remain same.<br /><br />3) Access order is affected by calling get(key), put(key, value) or putAll(). When a particular entry is accessed, it moves towards end of the doubly linked list, maintained by LinkedHashMap.<br /><br />4) LinkedHashMap can be used to create LRU cache in Java. Since in LRU or Least Recently Used Cache, oldest non accessed entry is removed, which is the head of the doubly linked list maintained by LinkedHashMap.<br /><br />5. Iterator of LinkedHashMap returns elements in the order e.g. either insertion order or access order.<br /><br />6. LinkedHashMap also provides a method called removeEldestEntry(), which is protected and default implementation return false. If overridden, an implementation can return true to remove oldest entry, when a new entry is added.Jackobnoreply@blogger.com