Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Introduction to the use of Map

Shulou Source: shulou.com Published: 2022-06-02 10:09:05 09月16日 Update

This article mainly explains "how to use Map". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Map.

Architecture of Map

Map is a mapping interface. Unlike List and Set, it does not inherit from the Collection interface. The content stored in Map is key-value pairs (key-value).

AbstractMap is an abstract class that inherits from Map and implements most of the API in Map. Other Map implementation classes can reduce duplicate coding by inheriting from AbstractMap.

SortedMap is an interface that inherits from Map. The content in SortedMap is the key-value pair of the sort, which is sorted through the Comparator.

NavigableMap is an interface that inherits from SortedMap. Compared with SortedMap,NavigableMap, there are a series of navigation methods, such as "get key-value pairs greater than / equal to an object", "get key-value pairs less than / equal to an object" and so on.

The main implementation classes of Map are HashMap, LinkedHashMap, TreeMap, HashTable and so on.

HashMap

Inherit from AbstractMap

Save unordered key-value pairs

Non-thread-safe, the element can be null

LinkedHashMap

Inherit from HashMap

Save ordered key-value pairs, which provide the order in which they are inserted by default, and can also be constructed to create the access order.

Non-thread safe, element cannot be null

TreeMap

Inherits from AbstractMap and implements the NavigableMap interface

Save ordered key-value pairs, sort the key by default, or construct a custom sort.

Non-thread safe, element cannot be null

HashTable

But it inherits from Dictionary and also implements the Map interface

Save unordered key-value pairs

Thread-safe, the element can be null

Source code parsing of Map

Entry

Interface Entry {K getKey (); V getValue (); V setValue (V value); boolean equals (Object o); int hashCode (); public static

Tags: Methods interfaces security elements content threads sorting usage ordering functions objects order learning programming practical deeper middle interest can pass most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Information MariaDB Shulou Technology Xiaomi