1. Overview of the Linkedhashmap class
Linkedhashmap: A hash table of the map interface ( guaranteed uniqueness ) and a list of links ( guaranteed order ) are implemented with a predictable sequence of iterations.
2. code example:
1 Packagecn.itcast_03;2 3 ImportJava.util.LinkedHashMap;4 ImportJava.util.Set;5 6 /*7 * Linkedhashmap: is the hash table and link list implementation of the map interface, with a predictable iteration order. 8 * guaranteed uniqueness of keys by hash table 9 * The chain list ensures that the keyboard is ordered ( The order of storage and removal is consistent) Ten */ One Public classLinkedhashmapdemo { A Public Static voidMain (string[] args) { - //To create a collection object -Linkedhashmap<string, string> HM =NewLinkedhashmap<string, string>(); the - //Creating and adding elements -Hm.put ("2345", "Hello"); -Hm.put ("1234", "World"); +Hm.put ("3456", "Java"); -Hm.put ("1234", "Java ee"); +Hm.put ("3456", "Android"); A at //Traverse -Set<string> set =Hm.keyset (); - for(String key:set) { -String value =Hm.get (key); -SYSTEM.OUT.PRINTLN (key + "---" +value); - } in } -}
Run the effect as follows:
Basic knowledge of Java Collection Framework Notes 58:map collection Linkedhashmap class overview