为什么 LinkedHashMap 没有实现 SortedMap?
Why does LinkedHashMap not implement SortedMap?
LinkedHashMap 显然是一个有序的Map。它根据插入排序。
那么为什么它不实现 SortedMap?
Hash table and linked list implementation of the Map interface, with
predictable iteration order. 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).
虽然排序地图是
A Map that further provides a total ordering on its keys. The map is
ordered according to the natural ordering of its keys, or by a
Comparator typically provided at sorted map creation time.
所以两者的存在是为了不同的目的,其中 LinkedHashMap 以相同的键插入顺序提供迭代,而 SortedMap 用于使用 Comparator 或 Comparable 进行排序
LinkedHashMap 显然是一个有序的Map。它根据插入排序。
那么为什么它不实现 SortedMap?
Hash table and linked list implementation of the Map interface, with predictable iteration order. 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).
虽然排序地图是
A Map that further provides a total ordering on its keys. The map is ordered according to the natural ordering of its keys, or by a Comparator typically provided at sorted map creation time.
所以两者的存在是为了不同的目的,其中 LinkedHashMap 以相同的键插入顺序提供迭代,而 SortedMap 用于使用 Comparator 或 Comparable 进行排序