Java hash table (Hash Table)

1. First introduce MAP

Map<K, V> is an interface that stores data in the form of key-value correspondence. **In the array, we index the content through the array subscript, and in the Map we index the object through the object. The object used for indexing is called the key, and the corresponding object is called the value. ** That is to index the value according to the value of the key.
HashMap is the implementation class of Map<K, V>. HashMap uses a hash table structure to store data, and the access sequence of elements cannot be guaranteed to be consistent. But the key value is unique and not repeated.

  Map<String, Integer> Ages = new HashMap<String, Integer>(); 
// 这是用接口的形式实现哈希表
// Key是String类型,Value是Integer类型
HashMap<String, Integer> Ages = new HashMap<String, Integer>();
//上面这种方法很不建议,因为Map接口下还有很多实现类,包括TreeMap等等。用第一种方法用接口实现,只需要替换后面的类。如果用第二种方法就需要重写,所以在这里推荐第一种方法创立哈希表。

2. Common methods of MAP

Insert picture description here

Guess you like

Origin blog.csdn.net/Mr_zhang66/article/details/114369443