SortedMap提供关于键的总体排序 的 Map
。该映射是根据其键的自然顺序进行排序的,或者根据通常在创建有序映射时提供的 Comparator
进行排序。
SortedSet提供关于元素的总体排序 的 Set
。这些元素使用其自然顺序进行排序,或者根据通常在创建有序 set 时提供的 Comparator
进行排序。
//接口SortedMap,继承了Map接口
public interface SortedMap<K,V> extends Map<K,V> {
Comparator<? super K> comparator();//基于Key的比较器
SortedMap<K,V> subMap(K fromKey, K toKey);//子视图
SortedMap<K,V> headMap(K toKey);//大于toKey的视图
SortedMap<K,V> tailMap(K fromKey);//小于fromKey的视图
K firstKey();//第一个Key
K lastKey();//最后一个Key
Set<K> keySet();//键集合
Collection<V> values();//值的集合
Set<Map.Entry<K, V>> entrySet();//元素实体集合
}
//接口SortedSet,继承了Set接口
public interface SortedSet<E> extends Set<E> {
Comparator<? super E> comparator();//基于值的比较器
SortedSet<E> subSet(E fromElement, E toElement);//子视图
SortedSet<E> headSet(E toElement);//大于toElement的视图
SortedSet<E> tailSet(E fromElement);//小于fromElement的视图
E first();//第一个元素
E last();//最后一个元素
}