Java LinkedHashMap学习

之前一直使用HashMap,今天学习一下LinkedHashMapapp

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.)spa

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

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

 


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.)input

这个方便特别有效果,若是一个模块须要使用一个入参map,拷贝map,并且复制品的key的顺序与入参map同样。(客户通常会欣赏:返回一个与给定的顺序同样的复制品)it

相关文章
相关标签/搜索