---restore content starts---
Map provides a more general method of storing elements, which are used to store element pairs (called "Keys" and "values"), where each key is mapped to a value.
Understanding Map interfaces and methods
Map Build
Map Update method: You can change the map content,
Clear () Removes all mappings from the map
Remove (Object key) removes the key and associated values from the map
Put (Object key,object value) relates the specified value to the specified key
Putall (Map T) copies all mappings in the specified map to this map
HASHMAP:
HashMap is a hash table based on the implementation of the map interface, in the form of Key-value, in HashMap, Key-value will always be treated as a whole, the system will calculate the location of Key-value according to the hash algorithm
1. Definition:
HASHMAP implements the map interface, which inherits the Abstractmap, where the map interface defines the rules for key mapping to values, while the Abstractmap class provides the backbone implementation of the map interface
public class Hashmap<k,v> extends abstractmap<k,v> implements Map<k,v>,cloneable,serializable
2 Constructors:
The HashMap provides three constructors:
HashMap (): Constructs an empty HashMap with default initial capacity (16) and default load factor (0.75)
HashMap (int initialcapacity): Constructs an empty HashMap with the specified initial capacity and default load factor (0.75)
HashMap (int initialcapacity,float loadfactor): Constructs a null HASHMAP with the specified initial capacity and load factor
Initial capacity, load factor, these two parameters are important parameters that affect the performance of HashMap, where capacity represents the number of buckets in the hash table, the initial capacity is the capacity to create a hashtable, the load factor is the hash table before its capacity automatically increases the size of a scale that can be reached, He measures the extent to which a hash table is used, and the larger the load factor, the higher the filling of the hash table,
3 Data structure:
The two most commonly used structures in Java are arrays and analog pointers (references), and almost all data structures can be implemented using these two combinations, HashMap is a "linked list hash", and the following is his data structure
It can be seen from the bottom of the HashMap is the array, but each item of the array is a chain, where the parameter initialcapacity represents the length of the array 4 storage implementation: 4.HashMap
When storing key-value pairs, the hash algorithm is used to repeat the key objects, which is highly efficient and has no order.
When storing a key-value pair, first call the Hashcode () method of the Key object to calculate a hash value, and find in the collection whether there is a hash value for the same key object.
If there is no key object with the same hash value, the key value pairs are stored directly.
If there is a hash value of the same key object, the same key object as the hash value is compared to equals ().
If the comparison result is false, the key value pair is stored.
The comparison result is true to overwrite the old value with the new value.
Java Map Collection Class