Java LinkedHashMap學習

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.