The commonly used map implementation classes in Java include: HashMap, HashTable, TreeMap.
One: HashMap
The bottom of the HashMap is actually the "array of linked lists", that is, each element actually holds a linked list, and the linked list holds objects with the same hash value.
1: New HashMap, is actually a new array
PublicHashMap (intInitialcapacity,floatloadfactor) {//Initialcapacity represents the capacity of the initialized HashMap, its maximum capacity is maximum_capacity = 1 << 30. if(Initialcapacity < 0) Throw NewIllegalArgumentException ("Illegal initial capacity:" +initialcapacity); if(Initialcapacity >maximum_capacity) initialcapacity=maximum_capacity; //Loadfactor represents its load factor, the default is default_load_factor=0.75, which is used to calculate the threshold critical value. if(loadfactor <= 0 | |Float.isnan (loadfactor))Throw NewIllegalArgumentException ("Illegal load factor:" +loadfactor); //Find a power of 2 >= initialcapacity intCapacity = 1; while(Capacity <initialcapacity) Capacity<<= 1; This. Loadfactor =Loadfactor; Threshold= (int) (Capacity *loadfactor); Table=NewEntry[capacity]; //create array init (); }
2: Inserting elements
Map in Java