. 1 Package Test; 2 . 3 Import the java.util.HashMap; . 4 Import java.util.Hashtable; . 5 . 6 public class MapDemo { . 7 public static void main (String [] args) { . 8 / * the Map - mapping 9 * 1 is java mapping top-level interface 10 * 2.Map is a container that is stored in key-value pairs 11 * 3. a complete mapping of both sets of values, a first set of values called Key- key, the second set of values called value Value- 12 * 4 key is unique, each corresponding to a key value. 13 * 5. In the map, the key and value pairs are, this structure is called the key-value pair. Therefore, a mapping is actually a plurality of key-value pairs consisting of 14 * 6. If a duplicate key is stored, then the corresponding value will be replaced. 15 * 7.Map not set, but Map is a member of the set of JAVA frame 16 * 8.JAVA set frame - the Collections Framework JAVA . 17 * comprising an array, set, and an interface map related classes: 18 is * Collection, Map, Arrays, , the Collections, the Iterator, Comparator, the Comparable . 19 * implementation class 20 is * the HashMap 21 is * 1. rely on the underlying data storage structure list an array + 22 maintain a list structure for each location on the array 4 * 23 each array 5. * a position called a bucket - bucket 24 * 2 array default initial capacity 16, the default load factor is 0.75f 25 * 3.JDK1.8, if the number of nodes in a single tub will list over eight twisted into a red-black tree, when the number of nodes is less than 7, will twist back to the list 26 * 4. If the specified the initial capacity of n, then 2 ^ x <n <= 2 ^ x + 1, is the actual capacity. 1 + X ^ 2 27 * when 5. the total number of> number has been used tub / tub load factor will be expansion. 28 * 6. Each expansion doubling, the bottom left is calculated based on 29 * After the expansion is completed, all the elements to be recalculated redistribute -rehash (expansion) 30 * reduce the number of rehash: 31 * 1. The initial capacity increases 32 * 2 suitable improve loading factor: 0.6 - 0.8 33 * 7. the same hash code of the same object class must be the same, different objects of the same class are typically different hash code 34 * 8. the larger the number of elements when the efficiency of rehash of the slower 35 * 9. smaller load factor, the greater the number of rehash, while resulting in a waste of space; loading factor greater, the element during insertion, the more the number of comparisons 36 * 10. The key to the tub in the discharge time , will first of all keys and key values of the tub is performed; if the same key, the value corresponding cover; key if not, the inserted end of the list 37 * 11 allows null null values and keys 38 * 12 the asynchronous thread safe formula 39 * * / 40 the HashMap <Integer, String> Hl = new new the HashMap <> (); 41 is H1.put (10, "L" ); 42 is H1.put (12 is, "because thousand years later " ); 43 H1.put (11," the world will have lost me " ); 44 H1.put (13," not affectionate hold your hand " ); 45 H1.put (14,"Kissing your forehead."); 46 is H1.put (10, "K" ); 47 System.out.println (Hl); 48 / * 49 * the Hashtable 50 * 1.HashTable first mapping is JAVA 51 * 2. allowed keys and values null 52 is * 3. + bottom against the array is stored in a linked list structure of 53 * 4 given initial capacity is the number, then the number is 54 * the synchronous thread safe 55 * 6. the default capacity is 11, a default load factor 0.75f 56 is * * / 57 is the Hashtable <Integer, String> the HT = new new the Hashtable <> (); 58 HT.put (. 1, "the small" ); 59 HT.put (2, "to get more fear" ); 60 HT.put (. 3, "every cry" ); 61 is HT.put (. 4, "every cry" ); 62 is HT.put (. 5, " each cry " ); 63 is HT.put (. 6," once every cry " ); 64 HT.put (. 7," every cry " ); 65 HT.put (. 8," every cry " ); 66 the HT .put (9, "each cry" ); 67 HT.put (10, "every cry" ); 68 HT.put (. 11, "once every cry" ); 69 HT.put (12 is, "every time cry"); 70 HT.put (13, "every cry" ); 71 is HT.put (14, "every cry" ); 72 HT.put (0, "each cry" ); 73 is System.out.println (the HT) ; 74 75 76 } 77 }