码迷,mamicode.com
首页 > 编程语言 > 详细

Java LinkedHashMap学习

时间:2017-06-26 12:39:35      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:ace   hashmap   dha   his   eterm   gen   note   key   span   

以前一直使用HashMap,今天学习一下LinkedHashMap

JavaDoc 注解:

Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if m.put(k, v) is invoked when m.containsKey(k) would return true immediately prior to the invocation.)

由Hash表和双向链表实现。有明确的遍历顺序,这个顺序一般是键插入的顺序。

另外,如果同样的key又插入了一遍,那么它还在原来的位置,不会受影响。

 


Map copy = new LinkedHashMap(m);   >>>This technique is particularly useful if a module takes a map on input, copies it, and later returns results whose order is determined by that of the copy. (Clients generally appreciate having things returned in the same order they were presented.)

这个方便特别有效果,如果一个模块需要使用一个入参map,拷贝map,而且复制品的key的顺序与入参map一样。(客户一般会欣赏:返回一个与给定的顺序一样的复制品)

Java LinkedHashMap学习

标签:ace   hashmap   dha   his   eterm   gen   note   key   span   

原文地址:http://www.cnblogs.com/shuada/p/7079713.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!