標籤: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學習