简体   繁体   中英

Implementation of java.util.Map using insertion order as order

The JDK documentation on java.util.Map states

The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not.

And the documentation on TreeMap states:

The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.

Is there any JDK implementation of Map that uses the order that elements were inserted into the map as the order?

java.util.LinkedHashMap :

This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map ( insertion-order ). Note that insertion order is not affected if a key is re-inserted into the map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM