Ordered LinkedHashMap and TreeMap

        Ordered means that for the data put into the map, when the data needs to be output, the user can know or predict in advance what kind of output order it is. Unlike HashMap this output order is agnostic.

1.LinkedHashMap

    LinkedHashMap allows null keys like HashMap, and internally maintains a doubly linked list. When iterative output, it can be output in insertion order (usually in insertion order, but also in access order), so the performance is slightly lower than HashMap. When re-inserting a piece of data (that is, putting an existing key), the insertion order will not be affected. LinkedHashMap frees users from unspecified, out-of-order Map implementations of HashMap and HashTable. And compared with TreeMap, there is no increased insertion cost.

2.TreeMap

    TreeMap is implemented based on a red-black tree. The keys of this map are ordered in two ways: one is to implement the Comparable interface for the key, and the other is to pass in the Comparator in the constructor.

Guess you like

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