1.Map Interface
The set of map interface definitions, also known as query tables, is used to store so-called "key-value" mapping pairs. A key can be considered an index of value, and an object that is a key cannot be duplicated in the collection.
According to the internal structure, the map interface has a variety of implementation classes, in which the common inner classes are the HashMap implemented by the hash table and the TREEMAP implemented internally for the ordered binary tree.
2.put () method
The map interface defines the put method for storing elements in the map:
-V put (K key,v value)
If the key is already contained in the collection, it will replace the value of the key, and the return value will be the corresponding value of the key (or null if not key-value).
3.get () method
The Get method for getting elements from a map is defined in the map interface:
-V Get (Object Key)
Returns the value object corresponding to the parameter key, or null if it does not exist.
4.ContainsKey () method
The map interface defines whether a key exists in the map:
-boolean ContainsKey (Object key);
Returns TRUE if the map contains the given key, otherwise false.
5.Hashcode Method
From the HashMap principle we can see that the return value of the Hashcode () method of key plays an important role in hashmap storing elements. The Hashcode method is actually defined in object. Then the method should be properly rewritten;
For objects that override the Equals method, it is generally appropriate to rewrite the Hashcode method that inherits from the object class (the Hashcode method provided by object returns the integer form of the memory address where the object resides).
Overriding the Hashcode method is two points: one, the consistency with the Equals method, which equals the two object whose Hashcode () method returns True, and the return value of the hashcode should be the same; Imagine that if the return value of the Hashcode method for many objects is the same, the efficiency of the hash table will be greatly reduced, and the Hashcode method can typically be generated automatically using the tools provided by the IDE (such as Eclipse).
6. Loading factor and HashMap optimization.
Capacity: capacity, the number of buckets (barrels) in the hash table, that is, the hash array size.
Initial capacity: initial capacity, when creating a hash table, the number of initial buckets, the default build capacity is 16, or you can use a specific capacity.
Size: The amount of data that is stored in the current hash table.
Load factor: Load factor, default value 0.75 (that is, 75%), when adding data to the hash table if
Use of Map