Map interface

The Map interface does not inherit from Collection. As a common container, Map maps a value according to the key. The key in a map is unique, and each key can only map one value.


Common interface methods:

1、    V put(K key, V value);Associates the specified value with the specified key in this map

2、    V get(Object key);

3、    V remove(Object key);

4、    void clear();

5、    Set<Map.Entry<K, V>> entrySet();

6、    boolean containsKey(Object key);

7、    boolean containsValue(Object value);


Map has two branches, HashMap, HashTable

2. HashTable is a thread-safe Map implementation


As can be seen from the above code, HashTable does not allow Value to be empty, and at the same time, it is necessary to obtain the hashCode of the key, so when the key is empty, a null pointer exception will be reported, so HashTable only allows non-null elements to be inserted, and neither key-value is allowed. Is empty.

Through initcapacity (initial capacity), loadFactor (load factor). Space can be saved by increasing the load, but the corresponding search time will increase

3. HashMap is similar to hashtable, but HashMap is not thread-safe.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326182203&siteId=291194637